开发者

Link JSP to Servlet and return ResultSet from Servlet to JSP

开发者 https://www.devze.com 2022-12-10 23:15 出处:网络
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

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 c开发者_如何学Pythonode 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消