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.
I'm working w/Servlets and JSP pages and want to be efficient with my memory. My question deals with request scope and session scope. If some information needs to only go from one page to the next, shouldn't I put this information in the request scope. And if I DO put this in the request scope, will this survive when I hit the back button to this page 5 pages later. Example: Page A requests an item price for my toy truck. Its $15434.00. (Nice truck huh?) Anyway, this information is put into the request scope. The informaiton is used on page B. I go on and go to page C then D then E and decide I need to hit the back button all the way back to page B. Will that information for the price of the truck still be there? Regards, Dale DeMott [ January 18, 2002: Message edited by: Dale DeMott ]
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
i think for what u describing a session scope is better . request wont do there, and for your question i think it wont survive the 5 pages back. request scope will be during that request only. if u forward that request to other servlets or jsp it will stay. but for other servlets and jsp that u havent actually forwarded that request (the same one) they wont have those variable. my siggestion is to try it yourself. put somthn in request move it to fiew other pages and hit the back button. actully ill try it later at home and post the correct answer.
whenever i think about a user using the back and forwards buttons on my web site 'applications', it just gives me a headache. Truly, I wish we could turn them off and on for purposes of 'flow control'.
There's one more issue u have to handle if ur providing back button functionality.. i.r regarding getting latest data.. Ofcourse how crucial this issue depends on ur application.. But one thing..session scope is must for this case.. Consider following scenario.. In shopping application i have 3 links.. Link1 : Add Item Link2 : Remove Item Link3 : Show all Added Items. Now i add three items A,B,C to my shopping cart.. Now i list all items.. By session scoped object u List A,B,C.. Now i delete Item B. Now i Press back button .. My listed items will be displayed as A,B,C which is wrong. But how important this type of scenario depends upon ur application. Rgds Manohar
Joined: Nov 02, 2000
I see what you mean. The situation I'm in is that I'm doing a very large query against an x500 database and wish to conserve memory. Right now the data that is queried is saved in the session scope. I wish to move this to the request scope. I also want the application to work when I hit the back button. If I put this information in the request scope AND pass the query via the URL, would this force the servlet to query the system again? Example http://localhost:8080/servlet/x500ServletQuery?lastName=Smith&firstName=Bob Any ideas??? Regards, Dale DeMott
I think you should not try to get tricky here. Leave the data in session scope - also store the query in the session. If you reach a point where you think the large data can safely be discarded, you can force the session to drop it with removeAttribute( "dataname" )- then if you need to rebuild it due to some arcane sequence of events, you can use the stored search string. Bill