• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

unable to pass value of resultset to servlet to jsp

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi



the bellow code is in my function which is in java class

want to pass the value return by the resultset to servlet and than servlet will pass all this value to jsp

How do i get that ???

its little urgent..please
[ February 13, 2007: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take the result set ...and store it as an attribute to the request object(if thats the scope you would like to choose) using request.setAttribute(....) and then access the resultset in you jsp...using request.getAttribute(....)

Then when the resultset is in your jsp....loop through and get the individual rows..
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


want to pass the value return by the resultset to servlet and than servlet will pass all this value to jsp



better... wrap resultset data in Collection and set with any scope you want.... and access within your servlet and iterate in jsp...
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which collection class should i use ???

there are 10 fields in my table.

and suppose if i use array list. than do i need 10 arraylist for each field ???
 
Milan Jagatiya
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can have any Collection ....

suppose you are getting users details in resultset . userid, username, password and firstname etc.
then create a bean for user with setter getter methods for userid, username, password and firstname.

fill this objects by fetching each row from resultset. refer below code...


now set "userList" in scope you want and iterate wherever you need....
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In short,

- get a bean (Value/Transfer Object)
- populate your bean
- add that to any preferred collection, typically an ArrayList
- do it for each row in resultSet

See the code posted by, Milan.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Milan Jagatiya:
while (resultSet.next()) {
userID = resultSet.getLong("userID");
userName = resultSet.getString("userName");
password = resultSet.getString("password");
firstName = resultSet.getString("firstName");
//constructor in User bean to set each property.
user = new User(userID, userName, password,firstName);
userList.add(i, user);
user = null;
i++;
}

[/CODE]



P.S. Its better to use the setter method instead of constructor arguments.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks all
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by Milan Jagatiya:
while (resultSet.next()) {
userID = resultSet.getLong("userID");
userName = resultSet.getString("userName");
password = resultSet.getString("password");
firstName = resultSet.getString("firstName");
//constructor in User bean to set each property.
user = new User(userID, userName, password,firstName);
userList.add(i, user);
user = null;
i++;
}
---------------------------------
Then from jsp, i can access the collection from <%%> tag, right? How about the user bean inside the collection? Can i access the bean by <jsp:useBean ..>?
I have

<jsp:useBean id="user" class="Login.UserBean" scope="session"/>
<%
Vector v = (Vector)request.getAttribute("userList");
Iterator i = v.iterator();
while (i.hasNext())
{
user = (UserBean)i.next();
%>

<li>
<a href="CORE/UserManager?cmd=get&id=
<jsp:getProperty name="user" property="id" /> ">
<jsp:getProperty name="user" property="pass" />
<jsp:getProperty name="user" property="name" />
</a>
<% } %>
But the output is always empty, the bean used in <jsp:getProperty ...> is an empty bean instead for a user bean as expected.
did i miss anything?
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey,

just check the scope to which you set the attribute and the scope from which you get are the same.

You are getting the userbean in the session scope. Is it the same session scope you have set?
[ May 24, 2007: Message edited by: Raghavan Muthu ]
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thai le. please do not post your own questions in someone else' threads. Rather, please start your own topic for your question. Thanks.
 
and POOF! You're gone! But look, this tiny ad is still here:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic