Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to pass a ResultSet from a servlet to jsp

Status
Not open for further replies.

4345487

Programmer
Dec 31, 2002
132
0
0
US
Hi,

I hope someone can help me with this question.

Does anybody knows how to pass a ResultSet from a servlet to a jsp using a session. I can pass a string OK.

For a string I do this in the servlet:

HttpSession session = request.getSession(true);
session.setAttribute("Test", "test string..........");
RequestDispatcher disp;
disp = getServletContext( ).getRequestDispatcher("/XX.jsp");
disp.forward(request, response);


Then in the JSP page i do this.

<%=session.getAttribute(&quot;Test&quot;)%>

and it works OK. But I need to pass a resultset

Thanks
 
A session attribute does not have to be a string.

But it is probably not a good idea to send the record set to the jsp. It is better to copy all of the recordset data into an object (a vector or hashmap may work) and send that to the JSP.

Good Luck
 
What Wiszh says is right.In addition to that don't forget to close your statement after you copy your records.

java.sql.Statement stmt = ....... ;
java.sql.ResultSet rs = stmt.executeQuery(&quot;....&quot;);
...
...
...
...
stmt.close();
/* then go to your jsp page...

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top