File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Session created 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 "Session created" Watch "Session created" New topic
Author

Session created

Adolfo Eloy
Ranch Hand

Joined: Mar 21, 2009
Posts: 146

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.


Adolfo Eloy
Software Developer
OCPJP 6
Niiraj Patel
Ranch Hand

Joined: Sep 17, 2011
Posts: 47
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

Joined: Mar 21, 2009
Posts: 146

Thank you Niiraj! Good explanation
 
 
subject: Session created