I am using SPRING MVC to develop a project to display a list of users in a JSP file. My Controller file has:
Map<String, Object> model = new HashMap<String, Object>();
model.put("user", userService.getUser()); //userService.getUser() returns a List
The JSP file has:
<c:if test="${!empty user}">
<table>
<tr>
<td>User Id</td>
<td>First Name</td>
<td>Last Name</td>
<td>Gender</td>
<td>City</td>
</tr>
<c:forEach items="${user}" var="user">
<tr>
<td><c:out value="${user.id}"/></td>
<td><c:out value="${user.firstName}"/></td>
<td><c:out value="${user.lastName}"/></td>
<td><c:out value="${user.gender}"/></td>
<td><c:out value="${user.city}"/></td>
</tr>
</c:forEach>
</table>
</c:if>
When displaying the above JSP file, java.lang.NumberFormatException: For input string: "id" is shown. Can anybody please help to find out the solution?
Thank you very much.
items="${user}" var="user"which user is what.. Replacing byvar="u"and usinguin theforeachmight helpuservariable within theforeachis actually a collection. Check that out.