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..
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....
- 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
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.
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?