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


does it work?

<p><%= myUsers.size()%></p>

      



I suggest writing as little java code as possible in jsp. You can use some tags taglib, jstl. eg. Place all business codes on the server. especially things likeb.DBConnection db = new db.DBConnection();

+5


source


 int count = myUsers.size();
            %>  
            <h1>User Management</h1>
            Total Subscribed Users: <p><%=count%></p>

      

0


source


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







All Articles