public class MyListener implements HttpSessionListener{
private int userNumber = 0;
public void sessionCreated(HttpSessionEvent arg0) {
userNumber++;
arg0.getSession().setAttribute("userNumber", userNumber);
}
public void sessionDestroyed(HttpSessionEvent arg0) {
userNumber--;
arg0.getSession().setAttribute("userNumber", userNumber);
}
}
<listener> <listener-class>com.test.MyListener</listener-class> </listener>
<body>
在线人数:<%=session.getAttribute("userNumber") %><br/>
</body>
public class MyServletContextListener implements ServletContextListener{
public void contextDestroyed(ServletContextEvent sce) {
}
public void contextInitialized(ServletContextEvent sce) {
}
}
public class MyHttpSessionListener implements HttpSessionListener{
public void sessionCreated(HttpSessionEvent arg0) {
}
public void sessionDestroyed(HttpSessionEvent arg0) {
}
}
public class MyServletRequestListener implements ServletRequestListener{
public void requestDestroyed(ServletRequestEvent arg0) {
}
public void requestInitialized(ServletRequestEvent arg0) {
}
}
public class MyServletContextAttrListener implements ServletContextAttributeListener{
public void attributeAdded(ServletContextAttributeEvent hsbe) {
System.out.println("In servletContext added :name = "+hsbe.getName());
}
public void attributeRemoved(ServletContextAttributeEvent hsbe) {
System.out.println("In servletContext removed :name = "+hsbe.getName());
}
public void attributeReplaced(ServletContextAttributeEvent hsbe) {
System.out.println("In servletContext replaced :name = "+hsbe.getName());
}
}
public class MyHttpSessionAttrListener implements HttpSessionAttributeListener{
public void attributeAdded(HttpSessionBindingEvent hsbe) {
System.out.println("In httpsession added:name = "+hsbe.getName());
}
public void attributeRemoved(HttpSessionBindingEvent hsbe) {
System.out.println("In httpsession removed:name = "+hsbe.getName());
}
public void attributeReplaced(HttpSessionBindingEvent hsbe) {
System.out.println("In httpsession replaced:name = "+hsbe.getName());
}
}
public class MyServletRequestAttrListener implements ServletRequestAttributeListener{
public void attributeAdded(ServletRequestAttributeEvent hsbe) {
System.out.println("In servletrequest added :name = "+hsbe.getName());
}
public void attributeRemoved(ServletRequestAttributeEvent hsbe) {
System.out.println("In servletrequest removed :name = "+hsbe.getName());
}
public void attributeReplaced(ServletRequestAttributeEvent hsbe) {
System.out.println("In servletrequest replaced :name = "+hsbe.getName());
}
}
public class User implements HttpSessionBindingListener,Serializable{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void valueBound(HttpSessionBindingEvent hsbe) {
System.out.println("valueBound name: "+hsbe.getName());
}
public void valueUnbound(HttpSessionBindingEvent hsbe) {
System.out.println("valueUnbound name: "+hsbe.getName());
}
}
public class User implements HttpSessionBindingListener,
HttpSessionActivationListener,Serializable{
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public void valueBound(HttpSessionBindingEvent hsbe) {
System.out.println("valueBound name: "+hsbe.getName());
}
public void valueUnbound(HttpSessionBindingEvent hsbe) {
System.out.println("valueUnbound name: "+hsbe.getName());
}
public void sessionDidActivate(HttpSessionEvent hsbe) {
System.out.println("sessionDidActivate name: "+hsbe.getSource());
}
public void sessionWillPassivate(HttpSessionEvent hsbe) {
System.out.println("sessionWillPassivate name: "+hsbe.getSource());
}
}
<?xml version="1.0" encoding="UTF-8"?> <faceted-project> <runtime name="Apache Tomcat v6.0"/> <fixed facet="java"/> <fixed facet="wst.jsdt.web"/> <fixed facet="jst.web"/> <installed facet="java" version="1.7"/> <installed facet="jst.web" version="2.5"/> <installed facet="wst.jsdt.web" version="1.0"/> </faceted-project>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有