Two Laptop Bag*
The moose likes Servlets and the fly likes requestDispatcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "requestDispatcher" Watch "requestDispatcher" New topic
Author

requestDispatcher

lathainses muthu
Greenhorn

Joined: Aug 06, 2008
Posts: 5
result set should be transfered from servlet to jsp
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by lathainses muthu:
result set should be transfered from servlet to jsp


can you explain in detail?

note:

---------------------------
please give meaningful subjectline
-------------------------------
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Hi,

If at all you are looking for making the resultset available to the called JSP, I would put the resultset into a session and call the jsp. You can also put the resultset into a request, call the jsp and can achieve the same results. By putting in session, I make sure that those values are available across all requests with in the session.


Thanks & Regards, SK
SCJP 5.0, DB2 - 800, DB2 - 803, SCDJWS (On the way)
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

Hi lathainses muthu
See How to ask questions on Javaranch

It will help you.


[Servlet tutorial] [Servlet 3.0 Cook Book]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Hey don't store a ResultSet into a session. A ResultSet is connected to the database on which the query was run. If you store a ResultSet then strange things might happen. The connection to the database might remain open. But I think it will not allow you to add a ResultSet object to a session (I once tried to return a ResultSet from a RMI server and it didn't work).

Instead use javax.sql.rowset.CachedRowSet i.e. store it in the session as it follows disconnected architecture.
For details refer to the JDK Documentation.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
JSPs are just for presentation not logic. You should process the ResultSet in the Servlet and transform the results into a presentation view which you place into the session.
Schandha Ravi
Ranch Hand

Joined: Oct 20, 2007
Posts: 167
Hi Ankit,

Can you explain how you were not able to add a Resultset to session and what was the problem you encountered.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

As peviously pointed out, resultsets in the session is a bad bad idea. Copy the data to a suitable collection and store that.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Originally posted by Schandha Ravi:
Hi Ankit,

Can you explain how you were not able to add a Resultset to session and what was the problem you encountered.


Well I didn't store the ResultSet in a session. I actually returned a ResultSet from a RMI method. But it gave me some error at run time(I don't remember what). I think it's because ResultSet is not Serializable. Now I think that if that's true then CachedRowSet will not work either as it is also not Serializable. Bear Bibeault is right, you should use some Collection or Map implementation...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

"Ankit G@rg", please check your private messages for an important administrative matter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: requestDispatcher