成都网站建设设计

将想法与焦点和您一起共享

servlet监听器-创新互联

监听器
ServletContextListener  监听servlet的初始化和结束
httpSessionListener      监听session的创建和结束 ,可以利用这个来统计在线登录的人数..
package com.zh;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class LoginListener implements HttpSessionListener{
private static int count;
public static int getCount(){
return count;
    }
public void sessionCreated(HttpSessionEvent arg0) {
// TODO Auto-generated method stub        count++;
    }

public void sessionDestroyed(HttpSessionEvent arg0) {
// TODO Auto-generated method stub        count--;
    }
}

注意要在web.xml文件中 设置

      com.zh.Test1
  


ServletContextAttributeListener    当servletContext对象被设置,删除,替换
HttpSessionAttributeListener      当HttpSession对象被设置,删除,替换
ServletRequestAttributeListener    当ServletRequest对象被设置,删除,替换
HttpSessionBindingListener        当HttpSession中添加属性和删除属性
注意: HttpSessionBindingListener不用在web.xml中设置
监听器servlet监听器

ServletContextListener 监听servlet的初始化和结束

10年积累的网站建设、成都网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站后付款的网站建设流程,更有遂昌免费网站建设让你可以放心的选择与我们合作。

httpSessionListener     监听session的创建和结束 ,可以利用这个来统计在线登录的人数..

package com.zh;

import javax.servlet.http.HttpSessionEvent;

import javax.servlet.http.HttpSessionListener;

public class LoginListener implements HttpSessionListener{

  private static int count;

  public static int getCount(){

     return count;

  }

  public void sessionCreated(HttpSessionEvent arg0) {

     // TODO Auto-generated method stub

     count++;

  }

  public void sessionDestroyed(HttpSessionEvent arg0) {

    // TODO Auto-generated method stub

     count--;

  }

}

注意要在web.xml文件中 设置

 com.zh.Test1

 

ServletContextAttributeListener   当servletContext对象被设置,删除,替换

HttpSessionAttributeListener     当HttpSession对象被设置,删除,替换

ServletRequestAttributeListener   当ServletRequest对象被设置,删除,替换

HttpSessionBindingListener       当HttpSession中添加属性和删除属性

注意: HttpSessionBindingListener不用在web.xml中设置


当前名称:servlet监听器-创新互联
文章分享:http://chengdu.cdxwcx.cn/article/dgcccp.html