Getting size of ArrayList in jsp page
Hi I am trying to get the total size of an arraylist but for some reason it is not displayed, the code below is used to display the size.
<%db.DBConnection db = new db.DBConnection();
ArrayList<User> myUsers =db.getAllUsers();
%>
Total Subscribed Users: <p><% myUsers.size();%></p>
thank
+3
source to share
4 answers
Some of them are clearly ripe to migrate from JSP, but depending on how it looks like, how your classes and methods are defined, this should work (JSP + JSTL):
<jsp:useBean id="db" class="db.DBConnection"/>
<c:set var="myUsers" value="${db.allUsers}"/>
Total Subscribed Users: <p>${fn:length(myUsers)}</p>
+13
source to share
You must do this to achieve this goal:
Total Subscribed Users: <p><%= myUsers.size(); %></p>
Alternatively, you can also:
Total Subscribed Users: <p><% out.print(String.valueOf(myUsers.size()));%></p>
The block of code you wrote in your question was "scriplet". The scriptlet itself does not contribute HTML.
For details see.
0
source to share