81,092
社区成员
发帖
与我相关
我的任务
分享
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
public class JavaBeanGetSessionValueSimple{
public void getSessionValue(){
WebContext ctx = WebContextFactory.get();
session = ctx.getHttpServletRequest().getSession();
String name = session.getAttribute("name");
System.out.println("name:" + name);
}
package com.bjsxt.drp.util.listener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class UserCountListener implements HttpSessionListener,HttpSessionAttributeListener {
private static int count = 0;
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
System.out.println("UserCountListener.sessionCreated()");
}
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
System.out.println("UserCountListener.sessionDestroyed()");
}
public void attributeAdded(HttpSessionBindingEvent event) {
// TODO Auto-generated method stub
System.out.println("name=" + event.getName());
System.out.println("name=" + event.getValue());
if (event.getName().equals("user")) {
count ++;
}
System.out.println("online count: " + count);
}
public void attributeRemoved(HttpSessionBindingEvent event) {
// TODO Auto-generated method stub
}
public void attributeReplaced(HttpSessionBindingEvent event) {
// TODO Auto-generated method stub
}
}[code=Java]
[/code]