Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session  RSS feed

 
Anu Pasricha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the need for creating session, when we can pass the value by other methods also, like query string.
Bye
Regards
Anu
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A "session" is just a conventient way to associate some Java objects in your web application with a particular sequence of requests and responses. In a lot of applications there's little point in passing everything back and forth every request, and sometimes the information that neeeds to be associated can't easily even be passed back and forth.
Imagine a typical sequence:
  • User logs in, application loads user preferences into a new session, hands back a "session id" to the browser.
  • User requests a page (sending the "session id"), application uses the loaded prefernces for that "session id" to format the returned page.
  • User chooses a customer from a list and returns the form with the session id, application loads all the information about that customer into the session from a databse and returns an edit page for that customer.
  • User changes some details on the edit form, submits the changed values and the session id, application updates the customer information in the session and returns an updated page.
  • User clicks a "save" button, application stores the changed customer information back to the datbase and unloads the customer information from the session.
  • ...


  • It makes no sense to send all that customer and preference information to the browser (as hidden fields, URL parameters etc.) and then back to the server again for every request. It's much simpler to just send a single "key" which identifies a group of loaded objects and leave the objects on the server, and that's a session!
    [ March 28, 2003: Message edited by: Frank Carver ]
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!