Which of the following statements are correct for distributable web-applications?
1. You cannot rely on the ServletContext to share data. 2. You cannot rely on ServletConfig for distributed web-applications. 3. Each JVM has a separate instance of a servlet context. 4. HttpSessions can be shared across distributable web-applications.
as per me - the answers are - 3,4..! 1,2 would have been ok if they had a CAN in the statements
but as per j2eecertificate webiste this is the answer
Answer 1, 3 and 4 are correct.
You cannot rely on the ServletContext to share data, each JVM in the distributed web-application has it own instance of the ServletContext. Setting an attribute on one host will not be replicated on the other host(s). The ServletConfig is a static class and can only be used to obtain parameters for the servlet in the servlet context. Even if many instances exists the data will be identical. HttpSessions can be used in a distributed environment. HttpSessions can serialize their attributes to a file-system or datastore and can be used across different environments.
please help !
SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ] Performance is a compulsion, not a option, if my existence is to be justified.
Sreeraj G Harilal
Joined: Apr 19, 2006
Each JVM in distributed environment has its own ServletContext object. That means :- Suppose our project is distributed to two JVMs (Say JVM1 and JVM2) and that has two Servlets called ServletA and ServletB. 1) A client request to ServletA. 2) The main container invokes ServletA of JVM1. ServletA adds some attributes to ServletContext object. 3) Another client request to ServletB. 4) The main container passivate the request to JVM2 container. 5) JVM2 container calls ServletB. 6) ServletB is trying to access attributes in the ServletContext object. Now think !! ServletB is having another context object, so the the attributes passed by the ServletA is not accessable to ServletB.
SCJP 5.0<br />SCWCD 1.4<br />Preparing for <b>SCEA</b>.<br /><b>"I prefer an interesting vice to a virtue that bores."</b>
Joined: Dec 25, 2006
you can rely on ServletContext to share data if the app is in single JVM. If the app is distributed with 2 JVMs, then 2 ServletContext objects will be created and the attributes set in ServletContext in one JVM wont be available in the other. so we cant share the data in Servlet context across JVMs.