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
signature.asc
Description: OpenPGP digital signature