This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem using getSession(boolean create)

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i want to do the same thing in servlets, then how i can do it!!!.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And reread the Naming Policy too
http://www.javaranch.com/name.jsp
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11854
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic