session监听器HttpSessionListener接口获得在线用户运行出错,帮忙看看
//hello类
package lognumber;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class hello implements HttpSessionListener {
String name;
public hello(String name){
this.name=name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void sessionCreated(HttpSessionEvent se) {
test.add(name);
}
public void sessionDestroyed(HttpSessionEvent se) {
test.delete(name);
}
}
//test类
package lognumber;
import java.util.ArrayList;
public class test {
static ArrayList list=new ArrayList();
public static void add(String name){// 添加用户
list.add(name);
}
public static void delete(String name){//删除用户
list.remove(name);
}
public static ArrayList getName(){
return list;
}
}
//Servlet1
package lognumber;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import lognumber.*;
public class Servlet1 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK ";
//Initialize global variables
public void init() throws
ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
IOException {
response.setContentType(CONTENT_TYPE);
&nbs