HUSNAIN SARWAR HUSNAIN SARWAR - 5 months ago 38
Java Question

How to Pass ArrayList From Servlet To JSP Page?

protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

String text = request.getParameter("text");
ServletContext context = getServletContext();
context.log(text);
StringProcess(text,context);
response.sendRedirect("sucess.jsp");

}

Answer

You can put that array list to either the sesion or request by calling setAttribute() method, like this:

request.setAttribute("arrName", arrObj);

Or

session.setAttribute("arrName", arrObj);

In your jsp page scriptlet, you can simply call request.getAttribute("arrName") or session.getAttribute("arrName") to get that array. Mind the type casting also.

If you use the core JSTL, you can loop through the array like this:

<c:forEach items="${arrName}" var="tmp">
...
</c:forEach>
Comments