Is it possible to have a servlet that contains an object (an ArrayList in this case) that then does the equivalent of displaying a jsp page and passing that object to the jsp page. In this case the ArrayList contains database results an I want to iterate through and display the results on the JSP page.
I am not using any MVC framework, is it possible to do this with the basic Servlet/JSP architecture.
Yes.
request.setAttribute("result", yourArrayList);then forward to the jsp:
using JSTL, in the jsp:
If you don’t want to use JSTL (but I recommend using it), then you can get the value using
request.getAttribute("result")in the JSP as well.Alternatively, but not recommended, you can use
request.getSession().setAttribute(..)instead, if you want toredirect()rather thanforward().