Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSessionListener does not work with Tomcat 4.1.24

 
Radoo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am preparing for the SCWCD, so when I read about event listeners I tried to do some tests, to see if it really works. I use Tomcat 4.1.24 and the ContextListener works fine. I tried to write also an HttpSessionListener class, in the same way, only for exercise purposes, but it is never called. I registered both classes in the same way in the web.xml :
<web-app>
<description>Empty web.xml file for Web Application</description>
<context reloadable="true">
</context>
<filter>
<filter-name>FilterName</filter-name>
<filter-class>package1.FilterClass</filter-class>
</filter>

<filter-mapping>
<filter-name>FilterName</filter-name>
<servlet-name>servlet1</servlet-name>
</filter-mapping>

<listener>
<listener-class>
package1.SessionListenerClass
</listener-class>
</listener>
<listener>
<listener-class>
package1.ContextListenerClass
</listener-class>
</listener>
........................
And here is the HttpSessionListener class that i wrote:
package package1;
import javax.servlet.http.*;
import java.util.*;

public class SessionListenerClass implements HttpSessionListener
{
public void sessionDestroyed(HttpSessionEvent evt){
HttpSession session = evt.getSession();
Integer sessAttr = null;
sessAttr = (Integer)session.getServletContext().getAttribute("atribut.sesiune");
if(sessAttr != null)
session.getServletContext().setAttribute("atribut.sesiune", new Integer(sessAttr.intValue()-1));
session.getServletContext().log(new Date() + " : " + "O noua sesiune distrusa !! :-)");
}
public void sessionCreated(HttpSessionEvent evt){
HttpSession session = evt.getSession();
Integer sessAttr = null;
sessAttr = (Integer)session.getServletContext().getAttribute("atribut.sesiune");
if(sessAttr != null)
session.getServletContext().setAttribute("atribut.sesiune", new Integer(sessAttr.intValue()+1));
else
session.getServletContext().setAttribute("atribut.sesiune", new Integer(1));
session.getServletContext().log(new Date() + " : " + "O noua sesiune initializata !! :-)");

}

}
Can anybody tell me, please what is wrong ???
Thanx a lot !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic