tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: HttpServletRequest#getSession(false) says the session is good, but session is still invalid!
Date Fri, 12 Dec 2008 17:59:03 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin,

Martin B. Smith wrote:
> With Tomcat 5.5 , I'm using the (what I assume to be typical) pattern:
> 
> --
> if(!request.isRequestedSessionIdValid() || request.getSession(false) ==
> null)
> {
>   // some code to bail out and return an error
> }
> 
> HttpSession session = request.getSession();


I've never done this. I typically just do:

HttpSession nonRequiredSession = request.getSession(false);

if(null === nonRequiredSession)
  // I gots no session
else
  // I have a session

> and yet, later on in my code, a call to session.setAttribute() throws
> the following exception (see bottom of email)... what am I doing wrong?

> Throwable/Exception cause: java.lang.IllegalStateException:
> setAttribute: Session already invalidated

Presumably, your code has called session.invalidate() during the
processing of the current request. I'm not sure what happens if you do this:

session = request.getSession();
session.invalidate();
session = request.getSession();
session.setAttribute("foo", "bar");

Will this fail on the setAttribute, or will the second getSession give
you a new session?

My guess is that your code does the above, but without the second
request.getSession(), so you end up with an invalidated session into
which you are trying to shove attributes.

Maybe you could post the code?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklCpmcACgkQ9CaO5/Lv0PDVsACfSIj+zQgexu2CWGcgTsdUzhDv
jpoAnjljuncyiTQP7u5uFagYS/Mwuw3b
=z0Dn
-----END PGP SIGNATURE-----

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


Mime
View raw message