tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roel De Nijs" <roel.den...@aquafin.be>
Subject Betr.: Re: Problem with HttpSessionListener
Date Wed, 11 Oct 2006 14:33:48 GMT
Juan,
 
what you also could do is, adjusting your code as follows:
    public void sessionCreated(HttpSessionEvent e){
        System.out.println("sessionCreated - id = " + e.getSession().getId());

        e.getSession().setAttribute("test", new String("testValue"));
    }

add this line 
System.out.println("sessionGetAttribute - id = " + request.getSession().getId());
before/after this line
String test = (String)request.getSession().getAttribute("test");
 
so you will be able to see if the get- and setAttribute happen on the same session and not
different ones

Roel

>>> Christopher Schultz <chris@christopherschultz.net> 11/10/2006 16:27 >>>

Juan,

> public class HttpTestListener implements HttpSessionListener {
> 
>    public void sessionCreated(HttpSessionEvent e){
>        e.getSession().setAttribute("test", new String("testValue");
>    }

Okay. I assume that there's an extra ")" end the end, otherwise your
code doesn't compile. I'll chalk that up to a copy-paste error.

>    <listener>
>        <listener-class>com.test.HttpTestListener</listener-class>
>    </listener>

Okay, that looks good.

> And, finally, in a servlet I try to recover the value of "test":
> ...
> String test = (String)request.getSession().getAttribute("test");
> ...
> 
> After this, the value of de variable test is null....
> 
> What have I to do if I want to recover the value of test?

I'm guessing that you are never setting that value.

Try changing your code to this:

    public void sessionCreated(HttpSessionEvent e){
        System.out.println("sessionCreated!!!");

        e.getSession().setAttribute("test", new String("testValue"));
    }

...and then check your catalina.out log (or standard output log,
whatever that is). If you aren't getting these messages, then your
listener is not configured correctly.

Make sure that your web.xml is actually in WEB-INF (I have sometimes
forgotten to copy web.xml from my development directory into the Tomcat
deployment, so double-check). You might consider doing a fresh install
of your application into the Tomcat webapp directory (or re-deploy the
WAR file) to make sure that Tomcat doesn't somehow have a stale copy of
web.xml lying around. Make sure you restart Tomcat, too ;)

I hope that helps.

-chris





**************************************************************
Disclaimer: zie www.aquafin.be   

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message