• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

return a specific session attribute from HttpSessionListener

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I have a HttpSessionListener that works fine.
I can get it to return a active session count and also each session ID.


Now I tried to return a specific attribute by using the following code:


but it returns null.
In my jsp I set it like so


Is this expected bahaviour?
If not, how can I return a listing of all sessions.getAttribute("myAttribute")

TIA!
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When does your JSP execute in relation to the listener mothods?
 
g forte
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure as to when the listener is called in relation to the jsp. I have the listener registered in web.xml and I get the System.out results almost exactly when I load the jsp which only contains the following code for testing.


Is there a way to control when the listener is called?

Perhaps this is not the correct design pattern for what I am trying to accomplish....my thoughts were that this would be a way to generate a listing of all users that are logged into a chat room.
Ideas?
Thanks for your input.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by g forte:
Not sure as to when the listener is called in relation to the jsp.



Then depending upon the JSP to create the scoped variable isn't a very good idea, is it?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to me you would get better results by adding the
HttpSessionAttributeListener interface to MySessionListener
because it has methods that get called when your code does a setAttribute()

Bill
 
g forte
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks,
not sure I understand you though.
Is it not possible to return an attribute from the listener or is this poor design or both?

Do you have any ideas as to a way to track people when they are in the chat room.

I figured that if I return the getAttribute("userName") and added it to a Application scoped variable (array,List,etc...) I could just print this variable to the page on each subsequent ajax call. Then when the sessionDestroyed method is called I could remove this userName from the variable.
Make sense?

Thanks again.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by g forte:

not sure I understand you though.



Your listener depends upon the JSP to set the scoped variable. Yet what assurances to you have the the JSP has ever been called?

Your design is poor because your listener depends upon the action of a JSP that it has no idea has ever executed or not.

So, how could you break that dependency?
[ July 18, 2006: Message edited by: Bear Bibeault ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The sessionCreated method is called when the session object is created, now when do you think that happens?
Answer: It happens BEFORE any of your session related code executes - when the servlet engine creates it before handing a reference to your code.
THEREFORE it can't possibly see attributes you set after getting the session instance.
Bill
 
mooooooo ..... tiny ad ....
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic