• Post Reply Bookmark Topic Watch Topic
  • New Topic

To put in the session or in the request ?

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I have a a question that I really want to know how the right answer.
Consider the following scenario :
The user clicks on the following link :
/details.do?isbn=1234567
The action goes to the database (throught Hibernate) and gets the required item and put it in the session scope and forwards the request to details.jsp page.
details.jsp has 'Add to cart' button, when the user clicks the previous button add the required item to the shopping cart and forwards the request to details.jsp to show a successful message.
So, why to put the item object in the session scope instead of request scope ?
Because when details.jsp redisplayed, an exception will be thrown because there is no an item instance in the request scope.
I can use the request scope but this will cost a SQL command (which already excuted) to retrieve the item again.
What do you think ?
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you already got the right answer. Put things in session scope if they are needed over more than one request. Did you want to hear something else?
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Sir, please check this :
http://www.coderanch.com/t/119366/HTML-JavaScript/Reimplementing-parts-app-DWR
Using the session scope was good until I decided integerate Ajax techniques.
[ January 24, 2007: Message edited by: John Todd ]
 
Paul Clapham
Sheriff
Posts: 21876
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't understand what that question has to do with this one. It doesn't make any difference whether the requests to your web application come from link clicking or from Javascript code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!