GeeCON Prague 2014*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes need help on question from j2eecertificate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "need help on question from j2eecertificate" Watch "need help on question from j2eecertificate" New topic
Author

need help on question from j2eecertificate

Niranjan Deshpande
Ranch Hand

Joined: Oct 16, 2005
Posts: 1277
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
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
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.

Simple


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>
VijayKumar Sivagnanam
Greenhorn

Joined: Dec 25, 2006
Posts: 26
Hi,

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.


SCJP 1.2 <br />SCWCD (94%)<br />SCBCD (preparing)
 
GeeCON Prague 2014
 
subject: need help on question from j2eecertificate