随笔 - 64  文章 - 9  trackbacks - 0
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(6)

我参与的团队

随笔分类(88)

随笔档案(92)

文章分类(142)

文章档案(182)

天基成员

学习园

我的海角

搜索

  •  

积分与排名

  • 积分 - 178745
  • 排名 - 320

最新评论

login.html

<html>
<body>
<font size = "16">
<form action = "chat.jsp" method = "post">
<center>
用户名: <input type = "text" name = "username"><br>
密码:<input type = "password" name = "password"><br>
                 <input type = "submit" value = "提交"><br>
</form>
</font>
</body>
</html>


chat.jsp

<%@ page contentType="text/html;Charset=gbk" import="java.util.*"%>
<%
String username = request.getParameter("username");
/*先检查有没有hash表*/
HashMap hs =(HashMap)application.getAttribute("userlist");/*application对象是用服务器创建所有用户共享,getAttribute检索与此修改项关联的属性。
返回:
用于修改的非 null 属性。*/

if(hs==null)/*如果没有,创建一个*/
 hs = new HashMap();
hs.put(username,username);/*把人加入到hash表*/
/*把hash表放到appplication中*/
application.setAttribute("userlist",hs);//将参数添加到application中
response.sendRedirect("userlist.jsp");//客户重定向
%>


usetlist.jsp

<%@ page contentType="text/html;Charset=gbk" import="java.util.*"%>
<meta http-equiv="refresh" content="3; url=userlist.jsp">/*3秒后跳转到本页面,用户端拉 <META HTTP-EQUIV="Refresh" CONTENT="?; URL=URL">(使用端自动更新 )*/
<html>
<body>
<font size="20">
<%
out.print("用户列表如下"+"<Br>");
HashMap hs= (HashMap)application.getAttribute("userlist");
Iterator it = hs.keySet().iterator();/*Iterator对集合进行迭代的迭代器,这个Keyset.iterator()迭代器是将hs中的元素按顺序读出来的*/
while(it.hasNext())//hasNext()如果仍有元素可以迭代,则返回 true。
{
 Object key = (Object)it.next();//返回迭代的下一个元素。
 Object username =(Object)hs.get(key);
out.print(username);
out.print("<br>");
}
%>
</body>
</html>
posted on 2009-05-03 11:08 鹏凌 阅读(94) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: