Search code examples
javajspstruts-1

how to send values from action class and view in jsp page


 public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        PrintWriter out=response.getWriter();
         FindBean lb=(FindBean)form;
        String bldgrp=lb.getBldgrp();
        String city=lb.getCity();
        String locality=lb.getLocality();
        String state=lb.getState();
        
        try {
             Class.forName("com.mysql.jdbc.Driver");
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/web","root","password");
Statement stmt = con.createStatement();
ResultSet rs=stmt.executeQuery("select name,email,phone from register where bldgrp = '" + bldgrp + "'AND state ='" + state + "'AND city ='" + city + "'AND locality ='" + locality + "'");

while(rs.next())
{

}
            
   
        }
        catch(Exception e)
{
out.println(e.getMessage());
}

i want that result stored in Resultset object rs is shown on next jsp page. i am using struts in netbeans ide


Solution

  • HttpSession session = request.getSession();
    session.setAttribute("myResultSet", rs);
    

    In you jsp:

    ResultSet rs = (ResultSet)session.getAttribute("myResultSet");
    

    Just store the object in the session and retrieve in your jsp. See above.