jsp(对session监听)

来源:互联网 发布:网络光端机价格 编辑:程序博客网 时间:2024/06/07 02:44

 1:jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" pageEncoding="UTF-8"%>



<!DOCTYPE HTML>
<html>
  <head>
    <title>对Application监听</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
  </head>
  <body>
    <%
      session.setAttribute("info", "监听器");
     %>
     <%
      session.removeAttribute("info");
      %>
  </body>

</html>


 2:listener(监听器)

package cn.com.filter;


import java.io.IOException;
import java.io.PrintWriter;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;


public class HttpSessionAttributeListenerDemo implements
HttpSessionAttributeListener {


@Override
public void attributeAdded(HttpSessionBindingEvent event) {


System.out.println("**增加属性-->属性名称:"+event.getName()+",属性内容:"+event.getValue());
}


@Override
public void attributeRemoved(HttpSessionBindingEvent event) {

System.out.println("**替换属性属性-->属性名称:"+event.getName()+",属性内容:"+event.getValue());
}


@Override
public void attributeReplaced(HttpSessionBindingEvent event) {
System.out.println("**删除属性-->属性名称:"+event.getName()+",属性内容:"+event.getValue());

}


}

0 0