我也是新手,好象是用JSP自带的内部对象application来解决,具体的你最好再找点资料看!
解决方案 »
- org.apache.jasper.JasperException: Unable to compile class for JSP:
- servlet中文乱码
- 这个交叉报表如何实现
- 这里不能运行高手帮我看看 谢谢
- 这问题有点纠结
- 严重问题:应答头中的charset,以及网页<meta 元素中指明的charset,是否只是告诉浏览器如何解析显示这个页面,并没有指定浏览器如何对送
- jsp页面选择显示区域问题
- 大家来聊聊。
- form中数组类型的property如何在validation.xml中校验啊????
- 请大家帮我查查问题
- 哪里有webwork框架的源码下载(100分)
- 数据传送原理,简单的理解问题
<HEAD>
<TITLE> New Document </TITLE>
<BODY BGCOLOR="#FFFFFF">
<%
//统计在线人数
application.setAttribute("counter",new Integer(0));
out.println(application.getAttribute("counter"));
//记录在线人名
application.setAttribute("onlineName",new String(""));
out.println(application.getAttribute("onlineName"));
%>
</BODY>
</HTML>
count.JSP(用来统计总人数并显示到页面):
<HTML>
<HEAD>
<TITLE> New Document </TITLE></head>
<BODY BGCOLOR="#FFFFFF" onUnload="javascript:cancel();">
<%
Integer i=(Integer)application.getAttribute("counter");
String name=(String)application.getAttribute("onlineName");
//StringBuffer total=new StringBuffer(name);
%><font color="blue">
<%out.println((String)Session.getAttribute("username"));%>您好:
</font>
<br><font color="blue">
当前在线人数:<%=i%>
</font>
<br>
<font color="red">
在线人总名册:<%out.println(name);%>
</font></BODY>
</HTML><HTML>
<HEAD>
<TITLE> New Document </TITLE></head>
<BODY BGCOLOR="#FFFFFF" onUnload="javascript:cancel();">
<%
Integer i=(Integer)application.getAttribute("counter");
String name=(String)application.getAttribute("onlineName");
%>
<br><font color="blue">
当前在线人数:<%=i%>
</font>
<br>
<font color="red">
在线人总名册:<%out.println(name);%>
<font color="blue">
<%//out.println((String)Session.getAttribute("username"));%>
</font>
</font>
<script language="javascript">
<!--
function cancel(){
<%
if(Session.getAttribute("username")!=""&&Session.getAttribute("username")!=null){
//cancelname为注销的人名
String cancelname;
cancelname=(String)Session.getAttribute("username");
//out.println(cancelname);//j为cancelname在总名册中的初始位置
//k为cancelname的总长度
//t为cancelname在总名册中的结束位置
int j,k,t;
j=name.indexOf(cancelname);
k=cancelname.length();
t=j+k;
//out.println(j);
//out.println(t);
///总名词中去除cancelname
StringBuffer total=new StringBuffer(name);
total=total.delete(j-4,t);
//总人数减1
i=new Integer(i.intValue()-1);
application.setAttribute("counter",i);
name=(String)total.toString();
application.setAttribute("onlineName",name);
//out.println("window.alert('"+name+"')");Session.setAttribute("username","");
}
%>
}
-->
</script>
</BODY>
</HTML>
定义一个int number;
public void sessionCreated(HttpSessionEvent ev){
number++;
]
public void sessionDestroyed(HttpSessionEvent ev){
number--;
]
类似这样,具体的功能你自己实现,即监听session的数量来控制在线人数!