How to display a list of objects in JSP through Servlet

Hello friends, Today I am going to show you how to display a list of objects using JSP and servlet. In this example, we will display a list of object using JSP pages and Servlet Controller.

In the controller, you have to set the list of object first and redirect the JSP page.

request.setAttribute("posts", posts);

Two ways you can display the data using JSP tag and JSTL tag also.

  <c:forEach items="${posts}" var="post">

  ArrayList<Post> posts=(ArrayList<Post>) request.getAttribute("posts"); 
  for (Post post: posts) {   

Hope it helps..

Leave a Reply