为何我添加的HttpSessionListener会没有效果?
自己写了一些servlet,然后写了一个myServletListener,内容如下:publicclassMyServletListenerimplementsServ...
自己写了一些servlet,然后写了一个myServletListener,内容如下:
public class MyServletListener implements ServletContextAttributeListener,ServletContextListener,HttpSessionListener,HttpSessionAttributeListener {
public void attributeAdded(ServletContextAttributeEvent scae) {
System.out.println("ServletContext attributeAdded");
}
public void attributeRemoved(ServletContextAttributeEvent scae) {
System.out.println("ServletContext attributeRemoved");
}
public void attributeReplaced(ServletContextAttributeEvent scae) {
System.out.println("ServletContext attributeReplaced");
}
public void sessionCreated(HttpSessionEvent se) {
System.out.println("sessionCreated");
}
public void sessionDestroyed(HttpSessionEvent se) {
System.out.println("sessionDestroyed");
}
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("contextDestroyed");
}
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("contextInitialized");
}
public void attributeAdded(HttpSessionBindingEvent arg0) {
System.out.println("Session attributeAdded");
}
public void attributeRemoved(HttpSessionBindingEvent arg0) {
System.out.println("Session attributeRemoved");
}
public void attributeReplaced(HttpSessionBindingEvent arg0) {
System.out.println("Session attributeReplaced");
}
}
然后将这个类添加进了web.xml:
<listener>
<listener-class>com.yyz.servlet.MyServletListener</listener-class>
</listener>
在tomcat重新启动之后,在控制台里可以看到:
ServletContext attributeReplaced
ServletContext attributeReplaced
ServletContext attributeAdded
ServletContext attributeAdded
ServletContext attributeReplaced
ServletContext attributeAdded
contextInitialized
关闭时也能看到
contextDestroyed
ServletContext attributeRemoved
按道理说,用浏览器浏览我刚刚写的servlet的时候,应该会看到sessionCreated和Session attributeAdded啊,为什么我无论是用myeclipse点open in browser或者直接打开IE输入localhost:8080都没有回话被创建或者回话属性被添加的提示呢?
想试着做一下统计累计浏览次数、在线人数、累计登录次数和已登录人数的功能
结果遇见这样一个问题…… 展开
public class MyServletListener implements ServletContextAttributeListener,ServletContextListener,HttpSessionListener,HttpSessionAttributeListener {
public void attributeAdded(ServletContextAttributeEvent scae) {
System.out.println("ServletContext attributeAdded");
}
public void attributeRemoved(ServletContextAttributeEvent scae) {
System.out.println("ServletContext attributeRemoved");
}
public void attributeReplaced(ServletContextAttributeEvent scae) {
System.out.println("ServletContext attributeReplaced");
}
public void sessionCreated(HttpSessionEvent se) {
System.out.println("sessionCreated");
}
public void sessionDestroyed(HttpSessionEvent se) {
System.out.println("sessionDestroyed");
}
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("contextDestroyed");
}
public void contextInitialized(ServletContextEvent arg0) {
System.out.println("contextInitialized");
}
public void attributeAdded(HttpSessionBindingEvent arg0) {
System.out.println("Session attributeAdded");
}
public void attributeRemoved(HttpSessionBindingEvent arg0) {
System.out.println("Session attributeRemoved");
}
public void attributeReplaced(HttpSessionBindingEvent arg0) {
System.out.println("Session attributeReplaced");
}
}
然后将这个类添加进了web.xml:
<listener>
<listener-class>com.yyz.servlet.MyServletListener</listener-class>
</listener>
在tomcat重新启动之后,在控制台里可以看到:
ServletContext attributeReplaced
ServletContext attributeReplaced
ServletContext attributeAdded
ServletContext attributeAdded
ServletContext attributeReplaced
ServletContext attributeAdded
contextInitialized
关闭时也能看到
contextDestroyed
ServletContext attributeRemoved
按道理说,用浏览器浏览我刚刚写的servlet的时候,应该会看到sessionCreated和Session attributeAdded啊,为什么我无论是用myeclipse点open in browser或者直接打开IE输入localhost:8080都没有回话被创建或者回话属性被添加的提示呢?
想试着做一下统计累计浏览次数、在线人数、累计登录次数和已登录人数的功能
结果遇见这样一个问题…… 展开
微测检测5.10
2023-07-11 广告
2023-07-11 广告
IEC62133 是国际电子电工委员会颁布的标准,做CB认证用的! EN62133 是欧盟颁布的,做CE认证用!深圳市微测检测有限公司 可以做IEC62133 也可以做EN62133 ,只是测试的标准不同,全国咨询电话:400-666-16...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询