I'm learning how to use Java Servlets and I've setup a toy example.
I have a servlet
with the following logic in the doGet
method:
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//HttpSession session = request.getSession();
List theList = new ArrayList();
theList.add(1);
theList.add(2);
theList.add(3);
request.setAttribute("intList", theList);
RequestDispatcher dispatcher = request.getRequestDispatcher("hello.jsp");
dispatcher.forward(request, response);
}
Then I have the following code in hello.jsp
:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Redirect Worked</h1>
<c:forEach items="${intList}" var="item">
${item}<br>
</c:forEach>
</body>
</html>
I expect my browser to show:
Redirect Worked 1 2 3
But all I see is:
Redirect Worked
What am I doing wrong?