My java classes are :
public class Name{
private String name;
private ArrayList<Phone> phoneList;
// plus getters and setters
}
public class Phone{
private String phone;
// plus getters and setters
}
Supose i have an ArrayList of Name, like:
ArrayList<Name> nameList = some method that returns an ArrayList<Name>
My servlet code would be:
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ArrayList<Name> nameList = some method that returns an ArrayList<Name>
request.setAttribute("nameList", nameList);
RequestDispatcher rd = request.getRequestDispatcher("someJSP.jsp");
rd.forward(request, response);
}
my jsp code would be:
<c:choose>
<c:when test="${not empty requestScope['nameList'] }">
<c:forEach var="name" items="${requestScope[' nameList '] }">
Name:${name.name }
<c:choose>
<c:when test="${not empty requestScope[' nameList.phoneList'] }">
<c:forEach var="phone" items="${requestScope ['nameList.phoneList'] }">
Phone:${phone.phone } </div>
</c:forEach>
</c:when>
<c:otherwise>
<span>The phone list is empty.</span>
</c:otherwise>
</c:choose>
</c:forEach>
</c:when>
</c:choose>
When i run the jsp file the nameList is not empty but the phone list is empty.
Somehow the phone list is lost and i don't know how to fix this.
When i run the jsp file the nameList is not empty but the pone list is empty.,
Because you didnt set the value for the
ponelist
Somehow the phone list is lost
It is not lost you dont have any method in the servlet to return the value from the getters and setters,
So need to have another list and set the attribute for the class
Phone
like the same above,Hope this helps !!