Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Behavior of ServletContext VS Behavior of HttpSession

 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please tell me the difference between the "Behavior of ServletContext" VS "Behavior of HttpSession" in Distributed Environment?
 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a distributed environment,
Each JVM will have a separate ServletContext. So you cannot depend on the Conetext level attributes while sharing attribute information

But the Session object is shared between all the JVM's present in the environment. You can test this out by implementing the HttpSessionActivationListener on your attributes.

The attributes will be passivated and then activated when they move from one server to another but in this case your attributes must be serializable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic