SRV.3.4.1 Context Attributes in a Distributed Container Context attributes are local to the VM in which they were created. This prevents ServletContext attributes from being a shared memory store in a distributed container. When information needs to be shared between servlets running in a distributed environment, the information should be placed into a session, stored in a database, or set in an Enterprise JavaBeans component..
Also in Servlet Spec 2.3 in Chapter 10, Application Lifecycle Events it states,
SRV.10.6 Distributed Containers In distributed web containers, HttpSession instances are scoped to the particluar VM servicing session requests, and the ServletContext object is scoped to the web container’s VM. Distributed containers are not required to propogate either servlet context events or HttpSession events to other VMs. Listener class instances are scoped to one per deployment descriptor declaration per Java virtual machine.
Here it says the Session is scoped to the particular VM servicing the session requests which means I cannot use sessions to store attributes to be shared, in a distributed container. This contradicts the previous one. Which one is correct? Somebody throw lights in this.
Arjun
Tom Arons
Greenhorn
Joined: Jan 04, 2002
Posts: 10
posted
0
I think these specs are maybe a detailed explanation to say that sessions can migrate to other VM's. Each VM has a separate instance of ServletContext and so do not rely on state information in ServletContext.
Arjun Anand
Greenhorn
Joined: May 24, 2001
Posts: 25
posted
0
Originally posted by Tom Arons: I think these specs are maybe a detailed explanation to say that sessions can migrate to other VM's. Each VM has a separate instance of ServletContext and so do not rely on state information in ServletContext.
That is what even I thought. But wanted to confirm if my understanding is right.
Cristian Daniel Ortiz Cuellar
Ranch Hand
Joined: Feb 02, 2011
Posts: 80
posted
0
Arjun Anand wrote:
Originally posted by Tom Arons:
I think these specs are maybe a detailed explanation to say that sessions can migrate to other VM's. Each VM has a separate instance of ServletContext and so do not rely on state information in ServletContext.
That is what even I thought. But wanted to confirm if my understanding is right.
can Somebody give a example of ServletContext Attributes??'
i understand ServletContext parameters maybe i am wrong..
can Somebody give a example of ServletContext Attributes??'
Think of the ServletContext as a global space where you can add objects to (and read objects from) that should available to all the Servlets. So basically any object you would like to be available can be added to the ServletContext as an attribute.
ServletContext init parameters are those parameters that you define in the web.xml
Regards,
Frits
Cristian Daniel Ortiz Cuellar
Ranch Hand
Joined: Feb 02, 2011
Posts: 80
posted
0
Frits Walraven wrote:
can Somebody give a example of ServletContext Attributes??'
Think of the ServletContext as a global space where you can add objects to (and read objects from) that should available to all the Servlets. So basically any object you would like to be available can be added to the ServletContext as an attribute.
ServletContext init parameters are those parameters that you define in the web.xml
Regards,
Frits
Thanks Great.. you mean servlets.. you mean (Servlets) As JSP View... i mean servletContext in a JSP as well right..