Reputation: 13
I am new in jsp and faced with one problem. I need to create jsp page, that displays data from servlet. Servlet code:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
CustomersDao customersDao = new CustomersDaoImpl();
List<Customers> custList = customersDao.getAllCustomers();
request.setAttribute("customersList", custList);
request.getRequestDispatcher("/test.jsp").forward(request, response);
}
jsp page code:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Test Page</title>
</head>
<body>
<%-->
<table border="1">
<tr>
<td>${requestScope['customers'].name}</td>
<td>${requestScope['customers'].lastname}</td>
<td>${requestScope['customers'].totalAmount}</td>
</tr>
</table>
<--%>
<table border="1">
<c:forEach var="element" items="${requestScope['customersList']}">
<tr>
<td><c:out value="${element.name}" /> TEST.name</td>
<td>${element.lastname} TEST.lastname</td>
<td>${element.totalAmount} TEST.totalAmount</td>
<td> ololo </td>
</tr>
</c:forEach>
</table>
</body>
</html>
When I send single object to jsp it's work normally (commented part of code). But when I try to send list, I can not separate object and browser shows me only test messages. So how do I fix it?
Upvotes: 1
Views: 454
Reputation: 46871
When I send single object to jsp it's work normally (commented part of code). But when I try to send list, I can not separate object and browser shows me only test messages.
You have forgotten to include the core tag library. that's why <c:forEach>
is not working but it works if you pass just single object.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
Upvotes: 1