1

Aim: Want to display the result which is fetched from database table into resultpage(response.jsp)

index.jsp > servlet > output.jsp

After a submit button in index.jsp , it calls the below servlet page.and below code succesfully fetches the data from database. not i wanting to know the ways that i can display the data into response.jsp(output page)

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>
  • Thanks -Sathish .
Sathish Kothandam
  • 1,530
  • 3
  • 16
  • 34
  • possible duplicate of [Resultset in JSP](http://stackoverflow.com/questions/11979932/resultset-in-jsp) –  Jan 10 '15 at 18:10
  • @RC .. Thanks for that. But i'm looking for another better or easy ways ? – Sathish Kothandam Jan 10 '15 at 18:18
  • I meant , instead loading into list , Any other direct way to use resultset ? – Sathish Kothandam Jan 10 '15 at 18:19
  • IMO using ResultSet directly in JSP is inappropriate because ResultSet is from model and your MVC becomes broken here. However maybe could you suggest API in pseudocode which would make you pleased. It would helps to give you better answers. – zimi Jan 12 '15 at 12:26

1 Answers1

0

You can set your resultset to view model and then add that view model as model attribute and use then use in for each loop on jsp page

Priyanka
  • 89
  • 4