469,290 Members | 1,868 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

retrieving data from the resultset into the jsp page

283 100+
hi frnds,
im doing some db related operations in my web project,im using mysql 5.0,i have the following piece of code in my action class-
Expand|Select|Wrap|Line Numbers
  1.                for(resultset = statement.executeQuery(s2); resultset.next();)
  2.             {
  3.                 s10 = resultset.getString(1);
  4.                 s11 = resultset.getString(2);
  5.                 s12 = resultset.getString(3);
  6.             }
  7.             resultset.close();
how do i retrieve the result of s10,s11,s12 in my jsp page?? wat changes do i have to do in my code??(i.e form bean and jsp page)??
wud appreciate ur thoughts...thanx in advance..
regards,
ajos
Sep 18 '07 #1
13 13979
r035198x
13,262 8TB
hi frnds,
im doing some db related operations in my web project,im using mysql 5.0,i have the following piece of code in my action class-
Expand|Select|Wrap|Line Numbers
  1.                for(resultset = statement.executeQuery(s2); resultset.next();)
  2.             {
  3.                 s10 = resultset.getString(1);
  4.                 s11 = resultset.getString(2);
  5.                 s12 = resultset.getString(3);
  6.             }
  7.             resultset.close();
how do i retrieve the result of s10,s11,s12 in my jsp page?? wat changes do i have to do in my code??(i.e form bean and jsp page)??
wud appreciate ur thoughts...thanx in advance..
regards,
ajos
You can write that same code in a JSP. Or extract the results in some other class and then send the results to the JSP as an attribute.
Sep 18 '07 #2
ajos
283 100+
You can write that same code in a JSP. Or extract the results in some other class and then send the results to the JSP as an attribute.
hi r035198x,
thanx for ur reply yet again.....ive opted for the 2nd solution i.e using setAttribute
this is wat ive done-

Expand|Select|Wrap|Line Numbers
  1. s10 = resultset.getString(1);
  2.                 httpservletrequest.setAttribute("s10", s10);
  3.                 s11 = resultset.getString(2);
  4.                 httpservletrequest.setAttribute("s11", s11);
  5.                 s12 = resultset.getString(3);
  6.                 httpservletrequest.setAttribute("s12", s12);
  7.  
  8.  
is this the right way?
how do i call this in my jsp page--->which is like this

[HTML]<font face="Tahoma">"+ s11 +"</font>[/HTML]
[HTML]<font face="Tahoma">" +s12+ "</font>[/HTML]
regards,
ajos
Sep 18 '07 #3
r035198x
13,262 8TB
hi r035198x,
thanx for ur reply yet again.....ive opted for the 2nd solution i.e using setAttribute
this is wat ive done-

Expand|Select|Wrap|Line Numbers
  1. s10 = resultset.getString(1);
  2.                 httpservletrequest.setAttribute("s10", s10);
  3.                 s11 = resultset.getString(2);
  4.                 httpservletrequest.setAttribute("s11", s11);
  5.                 s12 = resultset.getString(3);
  6.                 httpservletrequest.setAttribute("s12", s12);
  7.  
  8.  
is this the right way?
how do i call this in my jsp page--->which is like this

[HTML]<font face="Tahoma">"+ s11 +"</font>[/HTML]
[HTML]<font face="Tahoma">" +s12+ "</font>[/HTML]
regards,
ajos
Expand|Select|Wrap|Line Numbers
  1. <%
  2. String s10 = (String)request.getAttribute("s10");
  3. %>
Sep 18 '07 #4
ajos
283 100+
Expand|Select|Wrap|Line Numbers
  1. <%
  2. String s10 = (String)request.getAttribute("s10");
  3. %>
hi,
im getting the values of that particular columns as null....this is wat i did

<%String s11=(String)request.getAttribute("s11"); %>
<font face="Tahoma"> <%=s11 %> </font>
i think this is right...wats wrong with this????
Sep 18 '07 #5
r035198x
13,262 8TB
hi,
im getting the values of that particular columns as null....this is wat i did


i think this is right...wats wrong with this????
How did you call the JSP in the code?
Sep 18 '07 #6
ajos
283 100+
How did you call the JSP in the code?
ok this is how i called in the jsp page-->

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%String s11=(String)request.getAttribute("s11"); %>
  3. <font face="Tahoma"> <%=s11 %> </font>
  4.  
  5.  
where <%=s11%> is the values that will be displayed...
regards,
ajos
Sep 18 '07 #7
r035198x
13,262 8TB
ok this is how i called in the jsp page-->

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%String s11=(String)request.getAttribute("s11"); %>
  3. <font face="Tahoma"> <%=s11 %> </font>
  4.  
  5.  
where <%=s11%> is the values that will be displayed...
regards,
ajos
No that's not what I'm asking. Are you calling the JSP from a servlet? You should be. Otherwise if you are not using servlets then you should use the other option I talked about earlier.
Sep 18 '07 #8
ajos
283 100+
No that's not what I'm asking. Are you calling the JSP from a servlet? You should be. Otherwise if you are not using servlets then you should use the other option I talked about earlier.
my code,-->
Expand|Select|Wrap|Line Numbers
  1. for(resultset = statement.executeQuery(s2); resultset.next();)
  2.             {
  3.                 s10 = resultset.getString(1);
  4.                 httpservletrequest.setAttribute("s10", s10);
  5.                 s11 = resultset.getString(2);
  6.                 httpservletrequest.setAttribute("s11", s11);
  7.                 s12 = resultset.getString(3);
  8.                 httpservletrequest.setAttribute("s12", s12);
  9.             }
  10.  
this is in the action class...
im calling getAttribute in my jsp page
Sep 18 '07 #9
r035198x
13,262 8TB
my code,-->
Expand|Select|Wrap|Line Numbers
  1. for(resultset = statement.executeQuery(s2); resultset.next();)
  2.             {
  3.                 s10 = resultset.getString(1);
  4.                 httpservletrequest.setAttribute("s10", s10);
  5.                 s11 = resultset.getString(2);
  6.                 httpservletrequest.setAttribute("s11", s11);
  7.                 s12 = resultset.getString(3);
  8.                 httpservletrequest.setAttribute("s12", s12);
  9.             }
  10.  
this is in the action class...
im calling getAttribute in my jsp page
You should call the JSP from the code using
Expand|Select|Wrap|Line Numbers
  1. request.getRequestDispatcher("JSPPathAndName.jsp").include(request, response);
That way you pass the attributes to the JSP as well. You can't call this JSP by just double clicking it because then it wont have the attributes set.
Sep 18 '07 #10
ajos
283 100+
That way you pass the attributes to the JSP as well. You can't call this JSP by just double clicking it because then it wont have the attributes set.
You should call the JSP from the code using
Expand|Select|Wrap|Line Numbers
  1. request.getRequestDispatcher("JSPPathAndName.jsp").include(request, response);
im already forwarding the control to the jsp page using
Expand|Select|Wrap|Line Numbers
  1. return(mapping.findForward("pathname"));
the method u mentioned above,wud had gone well if i use servlets...but
Expand|Select|Wrap|Line Numbers
  1. return(mapping.findForward("pathname"));
also does wat RequestDispatcher does..
i better check my database records coz in the form bean ive set the value as null eg-private xyz=null; and since that is printing i think its ok...correct me if im wrong...

regards,
ajos
Sep 18 '07 #11
r035198x
13,262 8TB
im already forwarding the control to the jsp page using
Expand|Select|Wrap|Line Numbers
  1. return(mapping.findForward("pathname"));
the method u mentioned above,wud had gone well if i use servlets...but
Expand|Select|Wrap|Line Numbers
  1. return(mapping.findForward("pathname"));
also does wat RequestDispatcher does..
i better check my database records coz in the form bean ive set the value as null eg-private xyz=null; and since that is printing i think its ok...correct me if im wrong...

regards,
ajos
Yep check with println statements to see that you are forwarding non null values in the first place.
P.S I'm going to have to move this to the Java forum as it doesn;t have much to do with MySQL
Sep 18 '07 #12
ajos
283 100+
Yep check with println statements to see that you are forwarding non null values in the first place.
P.S I'm going to have to move this to the Java forum as it doesn;t have much to do with MySQL
hi r035198x,
i think its right.i checked the database,and to my disbelief the records entered in the table wasnt enough hence the queries requirement wasnt matching....
thanx for the help yet again.....(i think this will never stop!!!)
regards,
ajos
Sep 18 '07 #13
r035198x
13,262 8TB
hi r035198x,
i think its right.i checked the database,and to my disbelief the records entered in the table wasnt enough hence the queries requirement wasnt matching....
thanx for the help yet again.....(i think this will never stop!!!)
regards,
ajos
What will never stop?
Sep 18 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.