Two Laptop Bag*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How to test HttpSessionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How to test HttpSessionListener" Watch "How to test HttpSessionListener" New topic
Author

How to test HttpSessionListener

jami siva
Ranch Hand

Joined: Oct 16, 2009
Posts: 63
I created below Listener to track how many sessions are created. However, If I open number of browsers the below sessionCreated() method is executed only once. I thought every brower request treated as a seperate session. If it is true, below sessionCreated() method will call for every newly created session(In this case for every new browser request). Please let me know whether my understanding is right or wrong.

And how to test the below HttpSessionListener.




Thanks,
Siva
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Maybe because your browser is sharing the session.

Try with different browsers, or search in google how to do your browser to create a new session per tab.


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

If each request from a browser is treated as a new session, then what's the use of session? Try to open your page from different browsers (like one from Firefox, one from Chrome and one from IE). You'll get different session for each browser...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
jami siva
Ranch Hand

Joined: Oct 16, 2009
Posts: 63
Thanks Garg.

I tried with different browsers, one with IE and another with Mozilla, still I am getting only one session.
Apart from this, what should I do.

Thanks,
Siva
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1662
    
  25

I tried with different browsers, one with IE and another with Mozilla, still I am getting only one session.
Apart from this, what should I do.

How does your web.xml look like?

What URL do you use? Do you use tomcat, if so what version?

Regards,
Frits
A Phatak
Greenhorn

Joined: Sep 22, 2011
Posts: 24
What is the code in the Servlet that allows you to get the count of activeSessions. I suspect you are stuffing this in the session.setAttribute("activeSessionCOunter", activeSessions);

However, you will need another static method that returns this session counter


Now you can try this code in multiple browsers ...Chrome, IE, Saffari, or from multiple computers

I figure you will see number increase as sessions join!

jami siva wrote:I created below Listener to track how many sessions are created. However, If I open number of browsers the below sessionCreated() method is executed only once. I thought every brower request treated as a seperate session. If it is true, below sessionCreated() method will call for every newly created session(In this case for every new browser request). Please let me know whether my understanding is right or wrong.

And how to test the below HttpSessionListener.




Thanks,
Siva


ocpjp 6 (86%)
Sharad Kharya
Ranch Hand

Joined: Oct 15, 2008
Posts: 68
No. Sessions are referenced using cookies, and cookies are set per-client, not per-window.
Same session/session-timeout mechanism will be referred if client is sending requests from various different browser.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to test HttpSessionListener