开发者

Link JSP to Servlet and return ResultSet from Servlet to 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜