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
ArrayList orderList = (ArrayList ) request.getAttribute("theOrder");
//Unchecked cast from Object to ArrayList
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>
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)}
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>