完整的两个类,怎么看都没问题,结果就是不变
import java.util.*;
import javax.servlet.http.*;
public class SessionListener implements HttpSessionListener
{
protected static int count = 0;
public void sessionCreated(HttpSessionEvent event) {
count++;
}
public void sessionDestroyed(HttpSessionEvent event)
{ if (count > 0) { count–; } }
public static int getCount() {
return count;
}
}
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Servlet8 extends HttpServlet {
static final private String CONTENT_TYPE = “text/html; charset=GBK”;
public void init() throws ServletException { }
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println(“<html>”); out.println(“<head><title>Servlet1</title></head>”);
out.println(“<body>”);
out.println(“<p>在线人数” + SessionListener.getCount() + “</p>”);
out.println(“</body></html>”);
}
public void destroy() {
}
}