Ankit Kushwaha
Ankit Kushwaha

Reputation: 55

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

Upvotes: 0

Views: 5249

Answers (3)

Srinu Chinka
Srinu Chinka

Reputation: 1491

Find the below action code

ResultSet rs=stmt.executeQuery("select name,email,phone from register where bldgrp = '" + bldgrp + "'AND state ='" + state + "'AND city ='" + city + "'AND locality ='" + locality + "'");
Myobject obj = new MyObject();

while(rs.next()) {
    obj.setName(rs.getString(1));
    obj.setEmail(rs.getString(2));
    obj.setPhone(rs.getString(3));

}

request.setAttribute("myObj", obj);

in jsp:

<logic:present name="myObj">
Name : <bean:write name="myObj" property="name"/>
Email : <bean:write name="myObj" property="email"/>
Phone : <bean:write name="myObj" property="phone"/>
</logic:present>

Hopes this may be helpful ..

Upvotes: 2

Ahmed Tailouloute
Ahmed Tailouloute

Reputation: 85

Send it as an attribute of the HttpServletRequest, check setAttribute method

request.setAttribute("here_the_name",here_the_object);

In your JSP page, you can extract it with the getAttribute method

Object o = request.getAttribute("here_the_name");

You can send any object, you have just to cast it.

Upvotes: 2

brso05
brso05

Reputation: 13222

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.

Upvotes: 1

Related Questions