This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes session.invalidate() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "session.invalidate()" Watch "session.invalidate()" New topic
Author

session.invalidate()

Ankur Jain Kothari
Ranch Hand

Joined: Feb 08, 2010
Posts: 154
i ran a program...and then destroyed the session...i think all the attributes associted with the session are also killed when the session is destroyed...unbound is being called for each of the attributes....

is this right? or did i explain it wrong?


Do What You Wanna Be....Taking Things The Way They Come
scjp 1.6 91 percent, scmad 90 percent(rounded off to nearest integer)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Yes, attributes will be unbound when the session is invalidated.


[My Blog]
All roads lead to JavaRanch
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

But i think that the listener associated with the attributes will not be called in that case.

Correct me if i am wrong.
Ankur Jain Kothari
Ranch Hand

Joined: Feb 08, 2010
Posts: 154
when the session is destroyed...first the HttpSessionBindingListener is called...and then the HttpSessionAttributeListener
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

I tried it but HttpSessionAttributeListener was not being called when session was invalid.

I think i have to re verify it.
Ankur Jain Kothari
Ranch Hand

Joined: Feb 08, 2010
Posts: 154
it does get called...i tested it just now
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I'm not sure about HttpSessionAttributeListener, but HttpSessionBindingListener will be notified.
Ankur Jain Kothari
Ranch Hand

Joined: Feb 08, 2010
Posts: 154
how can i be wrong then..i just tried it
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

how can i be wrong then..i just tried it

Nobody is saying that you are wrong. However, "The container I'm using does it this way, so it works that way" is not a good argument. Containers sometimes do things unconventional things.
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Can both of you please let us know the containers you are using ?
Ankur Jain Kothari
Ranch Hand

Joined: Feb 08, 2010
Posts: 154
is it because am using tomcat 6? what if tis question comes in the exam?
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Yes, first HttpSessionBindingListener and then HttpSessionAttributeListener is being called.

I have tested it on TomCat 6
Ankur Jain Kothari
Ranch Hand

Joined: Feb 08, 2010
Posts: 154
thank god..thank you
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

But we have to test it again on an earlier version of TomCat
Ankur Jain Kothari
Ranch Hand

Joined: Feb 08, 2010
Posts: 154
actually i have read it here that the exam uses tomcat 5..i thought it woudnt matter....but am not changing any risk...switcing to 5.5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session.invalidate()
 
Similar Threads
Servlets and session...Do I need to?
session invalidation
session listener
Regarding Listeners
Session Migration Pg 269 HFSJ