import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class OnlineCounter implements HttpSessionListener {
private static long count=0;
public void sessionCreated(HttpSessionEvent arg0) {
count++;
}
public void sessionDestroyed(HttpSessionEvent arg0) {
count--;
}
public static long getCount(){
return count;
}
}
在要显示在线人数的页面top.jsp中导入
<%@ page import="com.suda.hxl.exam.common.*" %>
在线人数<%=OnlineCounter.getCount()%>
==================================================
各位师兄,这代码没问题吧,我试过在Action中使用OnlineCounter.getCount()是有结果返回的,就是直接放到JSP页面中使用就不行了,只导入那个包就报错,郁闷的很哟....
这个是只导入静态方法包后执行显示top.jsp时报的错误信息:
---------------------- 2013-3-20 0:08:20 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
Syntax error on token ";", delete this token
Stacktrace:
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
----------------------