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

Servlet - JSP interaction

 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have a problem in Servlet-JSP interaction. Actually, i have a servlet LogoutSt and a Update jsp page. The LogoutSt invalidates the session object that is used by the Update jsp, but the page directive's session attribute is 'true'. So, i'm not able to get the following condition to be "true"...
HttpSession s = request.getSession(false);
System.out.println(s.getId());
if (s != null) {
 
Vanchi Nathan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, not yet over...
How to get this condition "false" so that when this jsp page is revisited it should redirect the user to the Login Servlet?
Thanks in advance...
 
brad balmer
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if you have already figured out your issue, but I believe that jsp pages automatically create a session.
So, have you tried adding:
<#@ page session="false" %>
to the top of your page? If there is NOT a session (or invalid) then this page explicitly will NOT create one. Otherwise (without the attribute) I believe that the page automatically will create a session.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, JSP pages will create a session for you.
Your servlet has indeed killed the session and everything in it, but the moment the JSP executed it creates a new one.
A better test to check for session expiration is therefore to insert a known value in the session when you first start monitoring it (for example, session.setAttribute("userid", userID) in a servlet doing login, and check for the existence of that value (if (session.getAttribute("userid") != null) )when you want to know whether the session is still valid.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic