Meaningless Drivel is fun!*
The moose likes JSP and the fly likes storing parameters in request object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "storing parameters in request object" Watch "storing parameters in request object" New topic
Author

storing parameters in request object

Niral Trivedi
Ranch Hand

Joined: Nov 26, 2001
Posts: 46
Hi All,
I am developing an application in which one jsp page is going to have 4-5 multiple select drop down boxes each generated dynamically with data from database and holding some thousands values in each.
Now I am confused as to whether I should first call a servlet to populate data in individual vector for each drop down and then use RequestDispatcher to forward request to a jsp page with storing all those vectors in request object. So that in jsp page, I can call custom tag library to display each drop down by passing each vector for each drop down.
Or is it a bad idea to store such huge vectors in request object and forwarding request?
Or I should do all processing in jsp page directly instead of servlet?
All gurus, please help me with this.
Thank you.
Niral
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
Hi Niral
IMO you should go with the servlet solution, or better yet have the servlet pass the data access job off to some 'business object' that builds the Vectors/ArrayLists/Whatever to populate the drop-downs. It is good practice to use JSPs only for presentation, so they should just get the data from beans, or objects stored in request or session scope, without any knowledge of where the data came from.
Michael
[ October 24, 2003: Message edited by: Michael Fitzmaurice ]

"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
Niral Trivedi
Ranch Hand

Joined: Nov 26, 2001
Posts: 46
Actually I am going to have business data object do the processing. Question is, I can directly call those Data objects in JSP and then use them right there in JSP. Or I can use servlet first for validation and populate data access objects and then pass them to JSP through request object.
Will storing these big objects in request and passing them make site slower in response?
Thanks.
Niral
Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
My answer is still the same - pass the data to the JSP - it should not know where or how this data was created. I don't see that passing the data in the request is a performance issue - if it really is a lot of data, the biggest expense will probably be in pulling it from the database, and that is something your JSP/Servlet design will not be able to help with.
If you add these objects to the request, you are not using any additional memory other than for the pointer, so putting them in the request will not have a significant effect on memory usage. Is your concern memory usage or speed of response?
How dynamic must these lists be? Could you cache them? I would do that if at all possible - pull all the data from the db at start-up time and hold it in memory.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Michael has given you excellent advice. I would follow it closely.
I think this is a concept that eludes many JSP authors. Placing data in the attributes of the various contexts doesn't use up any additional memory (except for the very minimal hash entries in the attribuye maps). You're already using up the memory; they do not get copied into the contexts.
Perhaps the confusion arises from admonitions to be careful about putting too much data in the session context. But this admonition has less to do with the amount of memory being used than with the longevity of that data.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Niral Trivedi
Ranch Hand

Joined: Nov 26, 2001
Posts: 46
Michael,
Thank you very much for your advise. That has helped clear my doubts about storing objects in request object and performance issue.
Thanks again.
Niral
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: storing parameters in request object