• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

how would the sessionListener object be accessed

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

i saw this code in head first servlets & jsp page 259. it's a session listener to increment a value evergytime there's a session.


From where could i call the getActiveSession methods?

Does the servletContext object have access to it?
[ June 18, 2008: Message edited by: Christophe Verre ]
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like getActiveSessions() should be static, which would allow for BeerSessionCounter.getActiveSessions().
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your question is from where, then the answer is you can call it either from Servlet or from jsp.
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ali,

I was able to access the getActiveSessions() method from jsp file

here is the jsp file:


and here is the Java Code:



when i typed this in my browser http://localhost:8084/JSpBasics/ i am getting this result:

Number of Active sessions:0



i opened two browsers and typed the same url but i am getting the same result...When i open two browsers two sessions are created or only one
session created..

I accessed the same url from one of my collegue's machine(we all are in a network)But he is also getting the same result..


Guys,Please tell me in which case the output will be incremented..??

Thanks in Advance
Sudhakar Karnati
[ June 19, 2008: Message edited by: sudhakar karnati ]
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sudhakar, did you declare the listener in the DD and restarted the container?
 
sudhakar karnati
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jan,I forgot to include listener class in the xml..and now the count is incrementing..

One doubt i have is when i open each browser the count is incremented so all sessions are different..but when i open orkut in one browser and gmail in browser it does not ask me about the log in and it directly takes me to the inbox page..

According to the above program example each browser is creating seperate session so how come gmail browser gets the login credentials of Orkut opened in another browser...

if my above doubt is not valid..please leave it..

Thanks in Advance
Sudhakar Karnati
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sudhakar karnati:
Thanks Jan,I forgot to include listener class in the xml..and now the count is incrementing..

One doubt i have is when i open each browser the count is incremented so all sessions are different..but when i open orkut in one browser and gmail in browser it does not ask me about the log in and it directly takes me to the inbox page..

According to the above program example each browser is creating seperate session so how come gmail browser gets the login credentials of Orkut opened in another browser...

if my above doubt is not valid..please leave it..

Thanks in Advance
Sudhakar Karnati



gmail may not use jsp at all..
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dee Brown:
It seems like getActiveSessions() should be static, which would allow for BeerSessionCounter.getActiveSessions().



Not necessarily. One could use new BeerSessionCounter().getActiveSessions() .

Also, if you want to stay away from scriptles, you have to use non-static methods. E.g.
will only work if getSessionCount() is non-static. Otherwise it is not considered a bean property. (Had to find out the hard way, since it is not mentioned in HF).
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe orkut ang gmail use the same cookies.So when you log in into orkut , your login info will be stored in cookies.When you type gmail in same browser , it uses those cookies.
Try disabling cookies in your browser and gmail/orkut wont work.

Thanks,
Amol
 
Ali Khalfan
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jan Sterk:


Not necessarily. One could use new BeerSessionCounter().getActiveSessions() .

Also, if you want to stay away from scriptles, you have to use non-static methods. E.g.
will only work if getSessionCount() is non-static. Otherwise it is not considered a bean property. (Had to find out the hard way, since it is not mentioned in HF).




It's necessary to keep the counter variable static; otherwise you'd get the initial value every time you'd instantiante a new class the implements the SessionListener.
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try it, it works Static members have only one instance per class, not per object.
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic