File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes scope of request object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "scope of request object " Watch "scope of request object " New topic
Author

scope of request object

Tirthankar Dutta Chaudhuri
Ranch Hand

Joined: Feb 26, 2005
Posts: 48
Hi,
i have an requirement in which i retrive data from a java beans , The returned result set is huge say 10000 records , so display i need to have pagenation . Keeping such huge data in session nmakes it slow , so we have deceided to store it in request . when pagenation is done the the page is refreshed and new receords are shown , but i am losing the data as the when i am clicking on the links its a new request .
Alternatively i am getting bach to the controller servlet and again setting the data to the request object and then forwarding it again to the same page , it works that way . but can any one suggest any simpler method , say by which i can show the next 100 records without getting back to the servlet .
Is there any way by which i can keep the request object alive even when the page is refreshed or when a page is submitted , action being the same page .

Thanks
Tirthankar
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
it's a REQUEST object, which should give you a clear indication of its scope just from the name.


42
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

As Jeoren as already said , You can use the request object across requests. It is valid only a single request. The container may reuse the request object for a new request.
HttpSession is the object where you store data across multiple requests.


Keeping such huge data in session nmakes it slow , so we have deceided to store it in request .


If you have decided to store the data in request it will not be available in the next request. If you thinking about saving a reference to request object and retreieving the data from the saved reference in the next reuqest(PS:this does not work as I have already mentioned) why not store in the session , when your requirement can only be satisfied by HttpSession.


Groovy
Ashwin Kumar
Ranch Hand

Joined: Apr 07, 2005
Posts: 78
Use ArrayList to store the data. First retrive the first 100 records from DB and send the response to the client. immediately launch a thread that
loads the remaining records or all the records in the session object(ArrayList). for that u will have to pass the session object to the Thread which asynchronously loads the data.


Preparing SCEA..<br />SCBCD 5.0<br />SCWCD 1.4<br />SCJP 1.4
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Lookup the LIMIT or ROWNUM keyword (depending on what database you're using) to limit the number of rows returned from the database.

This will prevent you from tying up lots of memory with rows that may never be read. Shonak's suggestion is an advanced twist on this idea that will prepare the next block of rows for you while you're reading the current block.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Byron Estes
Ranch Hand

Joined: Feb 21, 2002
Posts: 313
The following is not a direct response, the gentlemen who posted before me have already covered that...but I thought I'd throw in a related tip...

Make sure you use a prepared statement and this can allow the database depending upon how advanced it is (...I know this works with Oracle), it will improve your performance through cacheing and bind variables. In this way if the sql is frequently submitted the DBMS will get the results from memory many times rather than going back to the physical disk.


Byron Estes<br />Sun Certified Enterprise Architect<br />Senior Consulant<br />Blackwell Consulting Services<br />Chicago, IL<br /><a href="http://www.bcsinc.com" target="_blank" rel="nofollow">www.bcsinc.com</a>
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
it's a REQUEST object, which should give you a clear indication of its scope just from the name.


ROFL!!!


I thought I was bad.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
You're bad, my trusty servant. But always remember who's the evil overlord!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scope of request object
 
Similar Threads
display
Refresh Header
Rereshing after modification / Listing
Refresh jsp page
Regarding vector