<head>
<title>My JSP 'index.jsp' starting page</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
itcast-filter2项目主页<br>
当前人数:${onlineNum }
<a href="${pageContext.request.contextPath }/validate.jsp">退出</a>
</body>
</html>
页面效果:
主要是使用setAttribute、removeAttribute方法。
ServletContextAttributeListener 专门用于ServletContext对象中的属性的变化情况
HttpSessionAttributeListener 专门用于session对象中的属性的变化情况
ServletRequestAttributeListener 专门用于request对象中的属性的变化情况
它们中的的 添加 、删除 、 修改的方法名称全部一致:

代码演示:
Jsp:
<%
//添加数据
session.setAttribute("addr", 111);
//替换数据
session.setAttribute("addr", 222);
//删除数据
session.removeAttribute("addr");
%>
器:
package cn.itcast.listener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
publicclassMyHttpSessionAttributeListenerimplements HttpSessionAttributeListener {
@Override
publicvoid attributeAdded(HttpSessionBindingEvent se) {
System.out.println("MyHttpSessionAttributeListener....attributeAdded...");
}
@Override
publicvoid attributeRemoved(HttpSessionBindingEvent se) {
System.out.println("MyHttpSessionAttributeListener....attributeRemoved...");
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/shouji/article-47577-14.html
泪奔
这是一个好演员
cp感也太足了
Great