- 论坛徽章:
- 0
|
//<测试Http会话监听器实例>:
//<classes目录下的Java代码>:
package cc.success;
import javax.servlet.http.*;
public class MyHttpSessionListener implements HttpSessionAttributeListener,HttpSessionListener
{
private HttpSession session;
public void sessionCreated(HttpSessionEvent arg)
{
this.session=arg.getSession();
System.out.println("****创建Session监听*****");
System.out.println("sessionID:"+this.session.getId());
}
public void sessionDestroyed(HttpSessionEvent arg)
{
System.out.println("***释放Session监听****");
}
public void attributeAdded(HttpSessionBindingEvent arg)
{
System.out.println("属性增加:"+arg.getName()+"--->>>>>>>"+arg.getValue());
}
public void attributeRemoved(HttpSessionBindingEvent arg)
{
System.out.println("删除属性:"+arg.getName()+"--->>>>>>>"+arg.getValue());
}
public void attributeReplaced(HttpSessionBindingEvent arg)
{
System.out.println("更改属性:"+arg.getName()+"--->>>>>>>"+arg.getValue());
}
}
//web.html代码:
<listener>
<listener-class>路径:<listener-class>
</listener>
我代码的路径是: cn.success.MyHttpSessionListener
//<测试JSP的代码如下:>
<%@ page contentType="text/html;charset=GBK"%>
<%
session.setAttribute("姓名","Vincent.Mr");
session.invalidate();
%>
__________________Vincent.Mr |
|