wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes problem using getSession(boolean create) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "problem using getSession(boolean create)" Watch "problem using getSession(boolean create)" New topic
Author

problem using getSession(boolean create)

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 357
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: 4727

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: 357
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: 4727

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: 357
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: 4727

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: 14688
    
  16

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: 11509
    
  95

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem using getSession(boolean create)