This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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
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
Joined: Nov 26, 2001
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
Joined: Aug 22, 2001
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.
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