我试图打印一个包含模型数据的列表,来自Customer class
,我使用jpa和servlet将数据传递给jsp。一旦搜索到servlet加载,就会获得异常java.lang.NumberFormatException: For input string: "firstName"
继承我的servlet方法:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
CustomerDAO dao = new CustomerDAO();
Customer customer = new Customer();
List<Customer> customers = dao.getAllCustomers();
request.setAttribute("customer", customers);
request.getRequestDispatcher("/Search.jsp").forward(request, response);
}
Jsp页面:
<tbody>
<c:forEach var="entry" items="${customer }">
<c:out value = "${entry}" />
<tr>
<td>
<div id="">
${customer.firstName }
</div>
</td>
<td>${customer.surname} </td>
<td> ${customer.code } </td>
<td> ${customer.customerType } </td>
<td><a id='' href='./Search?do=delete&code='>Delete</a></td>
</tr>
</c:forEach>
</tbody>
和stacktrace:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:335)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
servlet.Search.doGet(Search.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
答案 0 :(得分:1)
它应该是&#39; entry&#39;而不是&#39;客户&#39;
<tbody>
<c:forEach var="entry" items="${customer }">
<c:out value = "${entry}" />
<tr>
<td>
<div id="">
${entry.firstName }
</div>
</td>
<td>${entry.surname} </td>
<td> ${entry.code } </td>
<td> ${entry.customerType } </td>
<td><a id='' href='./Search?do=delete&code='>Delete</a></td>
</tr>
</c:forEach>
</tbody>