aspose 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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 145

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: 145

Thank you Niiraj! Good explanation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session created
 
Similar Threads
Sudden Logout Problem - Related to Concurrency?
Loosing sessions between pages
response.senRedirect does not seem to be working in filter
Session problem or the browser problem?
Tomcat 7 : JSESSIONID not being sent to client