Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!

Chithra Salam

+ Follow
since Mar 21, 2006
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Chithra Salam


Change the web.xml, put encoding="ISO-8859-1" instead of encoding="ISO-8851-1".Try it out.

Chithra Salam

Kamal Tripathi wrote:

On the same lines I wanted to ask if in a webapp's DD I configure an HttpSessionAttributeListener and also define a class A implementing HttpSessionBindingListener interface.

Now when objects of class A are set as attributes in session which listener will run first???


The Web container registers the listener instances according to the interfaces they implement and the order in which they appear in the deployment descriptor-means

If suppose a LisitenerclassA implements HttpSessionAttributeListener ,HttpSessionBindingListener and another class LisitenerclassB implements HttpSessionAttributeListener ,HttpSessionBindingListener

and in dd we declare
<listener><listener-class><com.example.LisitenerclassB ></listener-class></listener>
Now order of creation of instance of classes is LisitenerclassB ,LisitenerclassA.
and then order of registration of classes for events are LisitenerclassB regstrd against HttpSessionAttributeListener
LisitenerclassB regstrd against HttpSessionBindingListener
LisitenerclassA regstrd against HttpSessionAttributeListener
LisitenerclassA regstrd against HttpSessionBindingListener .

So a HttpSessionAttribute event [replace an attribute including a binding event]occur LisitenerclassB will be notified 1st and method invocation will be in the order attributeReplaced,valueBound- means in the order in which interface is been regstrd.

Kamal Tripathi wrote:On the same lines I wanted to ask if in a webapp's DD I configure an HttpSessionAttributeListener and also define a class A implementing HttpSessionBindingListener interface.

--- When you say configure an HttpSessionAttributeListener in DD that includes that class A implements HttpSessionAttributeListener as well rght .I think now you got the answer for this as well.
Chithra Salam
SCJP-85%,SCWCD-in progress.
Hi Lalit,

if I want to call action class of an application on JVM2 from JSP on JVM1,


If in case you need to pass session from one application to another application, then I think you need to pass the session as parameter.

Session persistance across JVMs stands for same application. Most of the people get wrong understanding on this.

Chithra Salam
SCJP-85%,SCWCD-In progress
From Marcus Green Tutorial :- The JSP/Servlet standard does not require that a web container supports distributed applications, but it must support the HttpSessionActivationListener interface, to allow code to be capable of supporting such an environment. The HttpSessionActivationListener has two methods.

public void sessionDidActivate(HttpSessionEvent se)
public void sessionWillPassivate(HttpSessionEvent se)

The specification mandates that a container may migrate a session to another JVM for purposes such as load balancing or fail-over. This type of capability is considered vital for the deployment of large scale web application

Session passivation is where inactive sessions are written to a persistent store. Session activation is the ability to a previously passivated session into memory from the persistent store. For an attributes to be migrated between distributed JVM's any attributes must implement the interface. This is not a very taxing programming task as Serializable is a marker interface i.e. it has no methods. .

With the exam perspective , the above things are enough to know.

If you hav the ask Q to implement then you shd knw few more things.

Load balancing with multiple machines either uses sticky sessions or symmetrical sessions.Sticky sessions put more intelligence on the load balancer, and symmetrical sessions puts more intelligence on the JVMs. The choice of which to use depends on what kind of hardware you have, how many machines you're using and how you use sessions.

Symmetrical Sessions
Symmetrical sessions happen with dumb load balancers like DNS round-robin. A single session may bounce from machine A to machine B and back to machine B. For JDBC sessions, the symmetrical session case needs the always-load-session attribute described below. Each request must load the most up-to-date version of the session.

Distributed sessions in a symmetrical environment are required to make sessions work at all. Otherwise the state will end up spread across the JVMs. However, because each request must update its session information, it is less efficient than sticky sessions.

Sticky Sessions
Sticky sessions require more intelligence on the load-balancer, but are easier for the JVM. Once a session starts, the load-balancer will always send it to the same JVM. Resin's load balancing, for example, encodes the session id as 'aaaXXX' and 'baaXXX'. The 'aaa' session will always go to JVM-a and 'baa' will always go to JVM-b.

Distributed sessions with a sticky session environment add reliability. If JVM-a goes down, JVM-b can pick up the session without the user noticing any change. In addition, distributed sticky sessions are more efficient. The distributor only needs to update sessions when they change. So if you update the session once when the user logs in, the distributed sessions can be very efficient.

In Simple words : -
1) When you say session across different JVM - It means same session of same web application in different JVM. There is a common misunderstanding on this.

Mean suppose I have an application like javaranch which is deployed in two machines[2 JVM]Server A and Server B for loadbalancing.Then if suppose 1st request for a servlet was fullfilled by ServerA , the next request frm same user can go to Server B .In this case session can persist across the JVM's if attributes are serialized.

2)In Symmetrical Sessions, When a request come,the loadbalancer is never bothered abt whether where any req has been fullfilled by this user,it just fwd he req to free Server [A or B]. The JVM and container will get the sessionid from cookie ,req url and will get the data from session.both JVM's nw have the session object/attribute .In Symmetrical Sessions, we need to get the session everytime as it may have got updated .

3)In Sticky sessions, logic is in loadbalacer. In the scen, Server A will be confg to generate sessionid strtg with som unique se eg:'aaaXXX' and 'baaXXX'. So when a req come loadbalancer will check the sessionid ,if it is empty it will route the req to any of the server.
if it strts with aaa, then that means a prev req has com and was fulfilled y ServerA, so loadbalancer will forward the req to same JVM.

Some chnage in DD is also reqd.I am not sure on that.

Sorry for the big reply.

Chithra Salam.
SCJP-85%,SCWCD-in Progress.

This Q may not be there in exam objectives,but was eager to know how container actually loads the instance.

What's the order in which below objects are loaded.

1)Context Listener
5)Tag class

I have written the objects on the order which I feel that container will load.

Please provide the inputs.

Chithra Salam
SCJP-85%,SCWCD-in progress.

In Servle 2.4 spec,Page 33 ,
[b]SRV.3.6 Multiple Hosts and Servlet Contexts[/b]
Web servers may support multiple logical hosts sharing one IP address on a server.
This capability is sometimes referred to as "virtual hosting". In this case, each
logical host must have its own servlet context or set of servlet contexts. Servlet
contexts can not be shared across virtual hosts.

What is virtual hosting/When is it used? Does the above statement says that In multiple hosting, There is more than one servlet context for a web application for each JVM.If so then how can we distinguish the attributes that we added/set on servletContext. ?

This way you can call the MusicCD methods as well.

-->How is it possible?The code wont get compiled right?

Chithra Salam
SCJP -85%,SCWCD-in progress.
Why we need to access ServletContext thr servlet config( this.getServletConfig().getServletContext(). ).I think in jspInit we can call this.getServletContext() , no need to access thr config.

Please correct me if I am wrong.
I don't think its a typo.According to my understanding the spec means.

1) The jsp Container will look for a .tag file under WEB-INF/tag or any subdirectory of WEB-INF/tag.

2)We can have any number of subdirectories.These subdirectories are meant only for better organization of web application directories.There is no relation between the directories.Means they are just folders that give a better organization of files.

3)The Container will consider each subdirectory as an implicitly defined tag library containing tag handlers defined by the tag files Or other wise container will consider each subdirectory as seperate tag library.

Hence in the example we have 3 tag libraries and 4 tag file .
1) /WEB-INF/tags/ --> contain 2 tag files a.tag and b.tag
2)/WEB-INF/tags/foo -->contain 1 tag file c.tag
3)/WEB-INF/tags/bar/baz/ --> contain 1 tag file d.tag.

Chithra Salam.A
SCJP 85%,SCWCD-in Progress.
Adding some more points ,

1)EVAL_PAGE is not a valid return from doAfterBody. The valid return values from doAfterBody are SKIP_BODY,EVAL_BODY_AGAIN.EVAL_PAGE is the valid return value from doEndTag.

2) Also as you are returning SKIP_BODY from startTag doAfterBody wont be invoked.It will get invoked only if in dd <body-content> is not declared empty, tag has body and if doStartTag return EVAL_BODY_INCLUDE.

3)If you haven't override doEndTag, the default return value is EVAL_PAGE.In your code as you have to print something implement doEndTag instead of doAfterTag.

Chithra Salam
MyIterTag implements IterationTag not BodyTag. So I think as EVAL_BODY_BUFFERED is not a field in IterationTag and so taghandler will not compile.

Chithra Salam.
[SCWCD -in progress,SCJP 1.4-85%]

I think option 5 InnerTag can get a reference to MiddleTag by calling TagSupport.getParent() method is the correct answer.

Option 2nd 3 are wrong as Classic tag cannot have Simple tag as parent but Simple tag can have Classic tag as parent and access it thr getParent or findAncestorWithClass.

Chithra Salam
[scwcd in progress,scjp 1.4 85%]
I am wondering on the fact that in the example given , 1st the request attrbute is been set ,then we are putting the values. So how can the request attribute contain Map with values instead of an empty Map.

Or am i wrong ?

Chithra Salam.A
Adding 1 more point, In standard action jsp:usebean if scope is not defined it has the default value =page scope .To mention session scope we need to explicitly mention the attribute scope.

Chithra Salam.A