This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Servlet - JSP interaction

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic