tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Davidson" <tim.david...@greenhatconsulting.com>
Subject RE: Checking for invalidated session
Date Fri, 01 Aug 2003 13:32:43 GMT
thanks.
the other option which I dont like was:
try
{
     session.invalidate();
}
catch (Throwable t)
{
     // Session is already invalid
}

-----Original Message-----
From: Murray [mailto:mpnix@optusnet.com.au]
Sent: Friday, August 01, 2003 2:14 PM
To: Tomcat Users List
Subject: RE: Checking for invalidated session


I'm trying to ensure that a session is newly created when I reach my index
page.  The logic is reversed from your question but I believe the principle
is the same inasmuchas I want to know whether or not a valid session exists.

  if (! session.isNew() )
  {
   session.invalidate();
   %>
   <rsp:sendRedirect>
    <rsp:encodeRedirectUrl>/scoutgroup/index.jsp</rsp:encodeRedirectUrl>
   </rsp:sendRedirect>
   <%
  }

The redirect is to cause the page to be reloaded after the invalidate()
since JSP, by default, creates a new session when the page is loaded.

In the body of the page I had a line
  <p>You are in session.  The session id is <%=session.getId()%>.
which produces "The session id is null" prior to inserting the redirect.
After the redirect was inserted the html was not sent to the browser until a
valid session was established at which time each visit to or browser refresh
of the page produced a new session id.

Someone with more than three months of playing with this as a spare time
hobby feel free to critique the solution please.

Murray

-----Original Message-----
From: Tim Davidson [mailto:tim.davidson@greenhatconsulting.com]
Sent: Friday, 1 August 2003 18:10
To: Tomcat Users List
Subject: RE: Checking for invalidated session


But surely theres a better way?
 Whould I be better off replacing "session.invalidate()" with "session =
null"?

-----Original Message-----
From: Justin Ruthenbeck [mailto:justinr@nextengine.com]
Sent: Thursday, July 31, 2003 6:44 PM
To: Tomcat Users List
Subject: Re: Checking for invalidated session


At 08:31 AM 7/31/2003, you wrote:
>How can you check to see if a session has already been validated?
>i.e.
>  if( !session.isInvalidated()) <-- what should go here?
>{
>         session.invalidate();
>}
>
>to prevent the following exception:
>"org.apache.jasper.JasperException: invalidate: Session already
invalidated"

If you don't want to just catch and ignore the JasperException, then use
something like this:

try
{
     session.getAttributeNames();
}
catch (java.lang.IllegalStateException isse)
{
     // Session is already invalid
}

justin

____________________________________
Justin Ruthenbeck
Software Engineer, NextEngine Inc.
justinr - AT - nextengine DOT com
Confidential
    See http://www.nextengine.com/confidentiality.php
____________________________________


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org



Mime
View raw message