Hi can someone please help why this is giving an error when trying to display the values in a JSP page. I don\'t have any number been converted or String been converted to N
The ${userRecords}
here
${userRecords.user_first_name}
${userRecords.user_middle_name}
is a List<User>
, however you're attempting to access it as if it's a single User
. This is not valid. In EL, a List
can only be accessed with an integer index, indicating the position of the list item you'd like to access, like so
${userRecords[0].user_first_name}
${userRecords[0].user_middle_name}
The exception is also basically telling that it expected an integer value instead of a string value. If you look closer at the stack trace, you'll see that a ListELResolver
is involved.
However, your concrete problem is bigger. You should actually be iterating over the list. Use the JSTL <c:forEach>
for that. E.g. (simplified from your odd code snippet):
<table>
<c:forEach items="${userRecords}" var="user">
<tr>
<td>${user.user_first_name}</td>
<td>${user.user_middle_name}</td>
</tr>
</c:forEach>
</table>
(note: keep the XSS attack hole in mind if you really intend to redisplay them as input values)
By the way, I'd work on your Java code conventions. Those underscores are really not Java-ish.