igrp系统中,对在线人数的统计和对用户的显示
这次主要是为了巩固我对map的认识
我们系统中,使用的是hashmap对用户登录id和总是进行统计
如下的实际情况便是我单独在jsp页面中显示出用户的总数和用户名称的例子
<%@ page language="java" import="java.util.*,javax.servlet.*,java.sql.*" pageEncoding="GBK"%>
<%@page import="cn.com.ivisions.datasource.connection.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'listusercountAndusername.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h1> 查看当前系统在线人数和实际名称</h1>
<%
//定义用户名
String username=null;
String sql=null;
Connection conn=null;
Statement sta=null;
ResultSet rs=null;
PreparedStatement ps=null;
int count=0;
Map listuserids=new HashMap();
listuserids=(Map)getServletConfig().getServletContext().getAttribute("operationUserIds");
int size=listuserids.size();
%>
登录系统的人员总数为: <%=size %>
<%
String operationids=null;
if(size>0)
{
Set operSet=listuserids.keySet();
Iterator operIter=operSet.iterator();
%>
<hr>
<table>
<tr><td>用户名</td><td>用户id</td></tr>
<%
while(operIter.hasNext())
{
operationids=(String)operIter.next().toString(); //该值获取的为用户的id值
//String counts=(String)listuserids.get(operationids);
sql="select realname from tbuser where userid="+operationids;
conn=DataSourceBean.getConnection();
try {
ps=conn.prepareStatement(sql);
rs=ps.executeQuery();
if(rs.next())
{
username=rs.getString(1);
count=1;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("捕获了结果集异常"+e.getMessage());
}
finally
{
DatasourceHelper.executeClose(rs, ps, null, conn);
rs=null;
ps=null;
}
%>
<tr><td><%=username %></td><td> <%=operationids %> </td></tr>
<% }
%>
</table>
<%
}
else
{
}
%>
</body>
</html>
posted on 2011-12-01 16:53 天马星空不脱离轨迹的猫 阅读(198) 评论(0) 编辑 收藏 举报