Link the JSP to the servlets and return the ResultSet from the servlet to the JSP

Hi, I pass the string to the servlet, which I then look at the access database and get the ResultSet object. I convert this to an ArrayList and redirect back to JSP

I am looking for a simple snippet of code to link to a JSP servlet using a simple link!

I hope this is the correct way to pass the results to jsp

+4
source share
1 answer

Use RequestDispatcher#forward() :

 public void doSomething(HttpServletRequest request, HttpServletResponse response) { List<Item> items = itemDAO.list(); request.setAttribute("items", items); request.getRequestDispatcher("page.jsp").forward(request, response); } 

JSP example:

 <table> <c:forEach items="${items}" var="item"> <tr> <td>${item.property1}</td> <td>${item.property2}</td> </tr> </c:forEach> </table> 

Hope this helps.

+7
source

All Articles