How to get array list size in java jsp?

后端 未结 4 767
一向
一向 2020-12-17 08:31

I have a form that ask for user to enter ID. This form is send to a servlet which checks database to see if user exist. If the user exists then it sends me back their ordere

相关标签:
4条回答
  • 2020-12-17 08:51
    ArrayList orderList = (ArrayList )  request.getAttribute("theOrder");
    
    //Unchecked cast from Object to ArrayList 
    
    0 讨论(0)
  • 2020-12-17 09:06

    you should set scope of your UserFound.jsp to request.

    ArrayList orderList = (ArrayList )  request.getAttribute("theOrder");
    
    <ul>
    <% If(orderList  != null) {%>
    
       <% for(String orderName : orderList ) { %>
          <li> <%= orderName %> </li>
       <% } %>
    
    <% }else{ %>
      No Order Found
    <% } %>
    
    
    </ul>
    

    OR

    ArrayList orderList = (ArrayList )  request.getAttribute("theOrder");
    <ul>
    <% If(orderList  != null) {%>
    
    <% for(int orderNum =0;i< orderList.size();++orderNum  ) { %>
       <li> <%= orderList.get(orderNum )%> </li>
    <% } %>
    <% }else{ %>
      No Order Found
    <% } %>
    </ul>
    
    0 讨论(0)
  • 2020-12-17 09:09

    Use fn:length function.

    Declare fn namespace on the begining of the JSP file

    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
    

    Later in the code

    ${fn:length(collection)}
    
    0 讨论(0)
  • 2020-12-17 09:09

    Newer versions of EL accept using the methods defined in the class of the object in EL expressions, so you can simply call the size() method:

    <span>Size: ${list.size()}</span>
    
    0 讨论(0)
提交回复
热议问题