• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext

 
Alain Boucher
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
What is the scope difference between ServletContext and Session.... I never used SessionContext but it appears that attribute in ServletContext have exactly the same scope as session attribute.
Thanks
Alain
 
Tom Adams
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically the session scope pertains to an individual´┐Żs user session. Any objects put into the session are retained until the session is invalidated (by the container or by code). The ServletContext pertains to a web-application (executing in a single JVM). Objects can be set/get from any servlet operating under that web application.
HttpSession scope = individual user session
ServletContext scope = web application
 
Alain Boucher
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok... but do you know a implementation example of that feature... on-line auction... chat... Is there someone who already used this feature... A servlet context attribute as the same behavior as a class variable in a servlet.
Alain
 
Tom Adams
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used the ServletContext to cache static lists - which I think is fairly common. For example one list was "valid" name prefixes like Mr., Ms., Mrs. etc. The jsp (thru a custom tag) rendered drop down selects using the list...
Other stuff commonly cached is front controller mappings and composite view components.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic