tags:

views:

831

answers:

1

Hi I am currently passing a string to a servlet which i then search an access database and get a ResultSet object. I convert this to an ArrayList and redirest back to the JSP

I am lookin for a simple piece of code to link to the Servlet to the JSP using a simple link!

I hope this is the correct way of passing a resultset back to the jsp

+4  A: 

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.

BalusC