When studying servlets, I ran into a problem: there is a servlet that sends attributes to the jsp page, a list:

req.setAttribute("name",list); req.getRequestDispatcher("/list.jsp").forward(req,resp); 

jsp page:

 <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>title</title> </head> <body> <c:forEach items="${name}" var="dev" > ${dev.id}<br> ${dev.firstName}<br> </c:forEach> </body> </html> 

Everything works fine, and when I launch jsp, which has a link to another jsp page, described above with the help of a tag (<a href="list.jsp"/>) , it stops displaying attributes that are passed to it.

    1 answer 1

    1. Write the parameter not in the request , but in the session , i.e. instead:

       req.setAttribute("name", list); 

      need to

       req.getSession().setAttribute("name", list); 

    1. You can write the same thing using the Java JSP Standard Tag Library (JSTL) :

      On the first page we set up the session session:

       <c:set var="list" value="${name}" scope="session"/> 

      on the second page we read:

       <c:out value="${sessionScope.list}"/> 

      Related link: How to pass data between JSP Pages using JSTL