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:[EMAIL PROTECTED]
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:[EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]