我試圖將包含servlet對象的ArrayList傳遞給JSP。但將ArrayList從servlet傳遞給JSP
Servlet的文件:
request.setAttribute("servletName", categoryList); //categorylist is an arraylist contains object of class category
getServletConfig().getServletContext().getRequestDispatcher("/GetCategory.jsp").forward(request,response);
JSP文件:
//category class
<% Category category = new Category();
//creating arraylist object of type category class
ArrayList<Category> list = ArrayList<Category>();
//storing passed value from jsp
list = request.getAttribute("servletName");
for(int i = 0; i < list.size(); i++) {
category = list.get(i);
out.println(category.getId());
out.println(category.getName());
out.println(category.getMainCategoryId());
}
%>
什麼的exeption? –
爲什麼不使用JSP-EL + JSTL來處理對象?其次,你如何從Servlet到JSP?使用重定向還是前進? –
@DebojitSaikia結果什麼也沒有顯示 – Pravin