演示SessionAttributeListener的使用方法
2007-12-23 12:35:50 来源:WEB开发网核心提示:import javax.servlet.http.Httpsession;import javax.servlet.http.HttpSessionAttributeListener;import javax.servlet.http.HttpSessionBindingEvent;public class Sess
import javax.servlet.http.Httpsession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
public class SessionAttribListen implements HttpSessionAttributeListener {
/** Creates new SessionAttribListen */
public SessionAttribListen() {
System.out.PRintln(getClass().getName());
}
public void attributeAdded(HttpSessionBindingEvent se) {
HttpSession session = se.getSession();
String id = session.getId();
String name = se.getName();
String value = (String) se.getValue();
String source = se.getSource().getClass().getName();
String message = new StringBuffer("Attribute bound to session in ")
.append(source).append("\nThe attribute name: ").append(name)
.append("\n").append("The attribute value:").append(value)
.append("\n").append("The session ID: ").append(id).toString();
System.out.println(message);
}
public void attributeRemoved(HttpSessionBindingEvent se) {
HttpSession session = se.getSession();
String id = session.getId();
String name = se.getName();
if (name == null)
name = "Unknown";
String value = (String) se.getValue();
String source = se.getSource().getClass().getName();
String message = new StringBuffer("Attribute unbound from session in ")
.append(source).append("\nThe attribute name: ").append(name)
.append("\n").append("The attribute value: ").append(value)
.append("\n").append("The session ID: ").append(id).toString();
System.out.println(message);
}
public void attributeReplaced(HttpSessionBindingEvent se) {
String source = se.getSource().getClass().getName();
String message = new StringBuffer("Attribute replaced in session ")
.append(source).toString();
System.out.println(message);
}
}
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
public class SessionAttribListen implements HttpSessionAttributeListener {
/** Creates new SessionAttribListen */
public SessionAttribListen() {
System.out.PRintln(getClass().getName());
}
public void attributeAdded(HttpSessionBindingEvent se) {
HttpSession session = se.getSession();
String id = session.getId();
String name = se.getName();
String value = (String) se.getValue();
String source = se.getSource().getClass().getName();
String message = new StringBuffer("Attribute bound to session in ")
.append(source).append("\nThe attribute name: ").append(name)
.append("\n").append("The attribute value:").append(value)
.append("\n").append("The session ID: ").append(id).toString();
System.out.println(message);
}
public void attributeRemoved(HttpSessionBindingEvent se) {
HttpSession session = se.getSession();
String id = session.getId();
String name = se.getName();
if (name == null)
name = "Unknown";
String value = (String) se.getValue();
String source = se.getSource().getClass().getName();
String message = new StringBuffer("Attribute unbound from session in ")
.append(source).append("\nThe attribute name: ").append(name)
.append("\n").append("The attribute value: ").append(value)
.append("\n").append("The session ID: ").append(id).toString();
System.out.println(message);
}
public void attributeReplaced(HttpSessionBindingEvent se) {
String source = se.getSource().getClass().getName();
String message = new StringBuffer("Attribute replaced in session ")
.append(source).toString();
System.out.println(message);
}
}
(出处:http://www.cncms.com)
Tags:演示 SessionAttributeListener 使用方法
编辑录入:爽爽 [复制链接] [打 印]更多精彩
赞助商链接