是否可以显示resultSet jsp的结果

时间:2015-01-10 18:05:52

标签: java jsp servlets

目标:想要将从数据库表中获取的结果显示到结果页面(response.jsp)

index.jsp> servlet> output.jsp的

在index.jsp中的提交按钮之后,它调用下面的servlet页面。下面的代码成功地从数据库中获取数据。我不知道如何将数据显示到response.jsp(输出页面)

的Servlet

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    int weeknum;
    RetouchClass retouch = new RetouchClass();
    weeknum = Integer.parseInt(request.getParameter("weeknum1"));
    //weeknum
    ResultSet weekNumResult = retouch.weekNum();
    request.setAttribute("result", weekNumResult);
    request.getRequestDispatcher("response.jsp").forward(request, response);

}

java Class

 public RetouchClass() {
        try {
            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public ResultSet weekNum() {
        try {
            retouchQuery = connection.prepareStatement("SELECT * FROM RETOUCH LIMIT 1 , 10 ;");
            resultSet = retouchQuery.executeQuery();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return resultSet;
    }

的response.jsp

 <table border="1">

    --- Want here to display the data from resultset

                </table>
  • 谢谢-Sathish。

1 个答案:

答案 0 :(得分:0)

您可以将结果集设置为视图模型,然后将该视图模型添加为模型属性,然后使用in为jsp页面上的每个循环