Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Session created

 
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

I've created a Servlet that print out some data to the user. But before to print this "some data to the user", I put the logic that follows to manage when a session was expired.
Regarding the code below, I didn't understand why when the first if is reached a new session seems to be created. I'm saying that because when the page is redirected to expired.jsp, there is a new session there. But I didn't wrote any code to create a new session. (I'm using getSession(false)).



So at the JSP I need to put this kind of logic:



Anybody know what's going on here? I'm preparing for certification so I think I need to understand it well.

Thanks.
 
Ranch Hand
Posts: 47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your thinking of request.getSession(false) is correct.

getSession(false) : Gives session if it is already exists, otherwise it gives NULL.

One fact about JSP : By default, When jsp is translated int Servlet, The translated servlet (Java version of JSP) has reference of HttpSession object.

So when you write request.getSession(false);,It is not creating new object, but, It gives you the implicit session object of jsp.

To Stop This behavior : Apply page directive to your jsp to disable default session object attachment by

By default it is


 
Adolfo Eloy
Ranch Hand
Posts: 146
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Niiraj! Good explanation
 
Evil is afoot. But this tiny ad is just an ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic