| Author |
how would the sessionListener object be accessed
|
Ali Khalfan
Ranch Hand
Joined: Nov 03, 2007
Posts: 126
|
|
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 ]
|
 |
Dee Brown
Ranch Hand
Joined: Jun 14, 2008
Posts: 94
|
|
|
It seems like getActiveSessions() should be static, which would allow for BeerSessionCounter.getActiveSessions().
|
 |
Srinivas Kumar
Ranch Hand
Joined: Jul 14, 2005
Posts: 52
|
|
|
If your question is from where, then the answer is you can call it either from Servlet or from jsp.
|
 |
sudhakar karnati
Ranch Hand
Joined: May 03, 2007
Posts: 93
|
|
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 ]
|
 |
Jan Sterk
Ranch Hand
Joined: Jun 06, 2008
Posts: 139
|
|
|
Sudhakar, did you declare the listener in the DD and restarted the container?
|
SCJP 1.4 (81%)<br />SCWCD 5 (95%)
|
 |
sudhakar karnati
Ranch Hand
Joined: May 03, 2007
Posts: 93
|
|
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
Joined: Jun 06, 2008
Posts: 139
|
|
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
Joined: Jun 06, 2008
Posts: 139
|
|
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).
|
 |
Amol Fuke
Ranch Hand
Joined: Apr 08, 2005
Posts: 129
|
|
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
|
"There are no mistakes, only lessons"
|
 |
Ali Khalfan
Ranch Hand
Joined: Nov 03, 2007
Posts: 126
|
|
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
Joined: Jun 06, 2008
Posts: 139
|
|
Try it, it works Static members have only one instance per class, not per object.
|
 |
 |
|
|
subject: how would the sessionListener object be accessed
|
|
|