Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session created

 
Adolfo Eloy
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.
 
Niiraj Patel
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic