Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to test HttpSessionListener

 
jami siva
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ankit Garg
Sheriff
Posts: 9579
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
jami siva
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sharad Kharya
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic