| Author |
problem using getSession(boolean create)
|
Naresh Chaurasia
Ranch Hand
Joined: May 18, 2005
Posts: 309
|
|
Hi, Java API docs say : If create is false and the request has no valid HttpSession, this method returns null. one.jsp [bold]two.jsp [/bold] I click at hyperline two in one.jsp after the session is expired (2 minutes in this case). When the control goes to two.jsp, it creates a new session, but since the session has expired, i should get null(according to API docs) and not new session object. [ June 21, 2006: Message edited by: Marc Peabody ]
|
SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
I'm going to close your other threads related to this very problem. Please try to keep all questions related to a single problem in a single thread. LOOK HERE! ******************** JSPs create a new session by default. If you want your second JSP to not automatically create a new session you must specify this directive in the second JSP: <%@ page session="false"> ******************** [ June 21, 2006: Message edited by: Marc Peabody ]
|
A good workman is known by his tools.
|
 |
Naresh Chaurasia
Ranch Hand
Joined: May 18, 2005
Posts: 309
|
|
|
If i want to do the same thing in servlets, then how i can do it!!!.
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
|
Servlets do not create a session by default. There are no special directives or other tricks necessary to make the same thing work in a servlet. I'm assuming that's what you're asking.
|
 |
Naresh Chaurasia
Ranch Hand
Joined: May 18, 2005
Posts: 309
|
|
|
yes thats true, but the problem i am facing is that once my session is expiring sessionDestroyed(HttpSessionEvent sessionEvent) of HttpSessionListener is called. Now the user is not aware that the session has expired or not... if he clicks at any of the hyperlinks (after the session is expired), then i have to check whether the session is expired. I do it by using request.getSession(false) to redirect him to sessionExpired.jsp. But the problem is request.getSession(false) creates a new session for the same user (Browser, the sessionID of new session is different from first one). So i have no way to know that the session has expired .......to take appropriate action
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
Originally posted by N Chaurasia: But the problem is request.getSession(false) creates a new session for the same user
NO, IT DOESN'T! I believe you are ignoring my posts. I've explained how it works. Please read them again.
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
And reread the Naming Policy too http://www.javaranch.com/name.jsp
|
[My Blog]
All roads lead to JavaRanch
|
 |
Andrew Monkhouse
author and jackaroo
Marshal Commander
Joined: Mar 28, 2003
Posts: 10823
|
|
Thanks for helping Satou, but as there are at least 38 people with the surname Chaurasia in the New York state alone (picking a state at random), it is quite possibly N Chaurasia's real name. And we do allow initials for the first letter. Regards, Andrew
|
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
|
 |
 |
|
|
subject: problem using getSession(boolean create)
|
|
|