how can i pass a object parameter from a servlet to a jsp page?
the object i want to pass is a list of item, item class described below :
class item{
String val1
String val2
String val3
}
//with getter setters
How can i pass items ( List items = new ArrayList() ) from a servlet to a jsp page and what do i have to add in the jsp to access the objec开发者_运维问答t ?
In the servlet you can store the object in the request scope.
getRequest().setAttribute("items", items);
Where items is your ArrayList of items.
On the JSP page you can access it in a number of ways. For example, using JSTL:
<c:forEach items="${items}" var="i">
${i.val1}
</c:forEach>
In the servlet:
httpRequest.setAttribute("myItem", item);
then forward to the JSP, and then in the JSP:
${myItem}
精彩评论