在servlet代码中,使用指令
request.setAttribute("servletName",categoryList)将您的列表保存在请求对象中,并使用名称“ servletName”进行引用。顺便说一句,使用然后使用名称“ servletName”作为列表是很令人困惑的,也许最好将其命名为“列表”或类似名称:
request.setAttribute("list", categoryList)无论如何,假设您不更改您的Serlvet代码,并使用名称“
servletName”存储列表”。当您到达JSP时,有必要从请求中检索列表,为此,您只需要
request.getAttribute(...)方法。
<% // retrieve your list from the request, with casting ArrayList<Category> list = (ArrayList<Category>) request.getAttribute("servletName");// print the information about every category of the listfor(Category category : list) { out.println(category.getId()); out.println(category.getName()); out.println(category.getMainCategoryId());}%>


