&lt;!--this file are written by fancy--&gt;<br>
&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;title&gt;<br>
login the first chat room <br>
&lt;/title&gt;<br>
&lt;/head&gt;<br>
&lt;%@ page import=&quot;java.util.Vector&quot;
%&gt;<br>
&lt;%@ page contentType=&quot;text/html;charset=gb2312&quot;
%&gt;<br>
&lt;%@ page import=&quot;java.util.Hashtable&quot;
%&gt;<br>
&lt;%@ page import=&quot;java.util.Date&quot;
%&gt;
<p>&lt;%<br>
byte[] username_p;<br>
String username_t=request.getParameter(&quot;username&quot
;<br>
username_p=username_t.getBytes(&quot;ISO8859-1&quot
;<br>
String username=new String(username_p);<br>
boolean boolcanlogin=true;<br>
%&gt;</p>
<p>&lt;%<br>
Vector temp=new Vector();<br>
String tempuser;</p>
<p>//*****************************************************************************<br>
temp=(Vector)getServletContext().getAttribute(&quot;chat1User&quot
;<br>
for(int i=0;i&lt;temp.size();i++)<br>
{<br>
tempuser=temp.elementAt(i).toString();<br>
if(username.equals(tempuser))<br>
{<br>
boolcanlogin=false;<br>
}<br>
}<br>
//*****************************************************************************<br>
if (username.equals(&quot;&quot
)<br>
{<br>
boolcanlogin=false;<br>
}</p>
<p>if (username.equals(&quot;每一个人&quot
)<br>
{<br>
boolcanlogin=false;<br>
}</p>
<p>if (username.equals(&quot;all&quot
)<br>
{<br>
boolcanlogin=false;<br>
}</p>
<p>if (username.length()&gt;8)<br>
{<br>
boolcanlogin=false;<br>
}<br>
//*****************************************************************************<br>
if(boolcanlogin==true)<br>
{<br>
temp.addElement(username);
//如果检查通过则在用户向量中加入新的用户名<br>
getServletContext().setAttribute(&quot;chat1User&quot;,temp);<br>
session.putValue(&quot;username&quot;,username);
//设置session记录用户名 <br>
//添加欢迎信息到消息向量里<br>
Vector tempmsg=(Vector)getServletContext().getAttribute(&quot;chat1Msg&quot
;<br>
tempmsg.addElement(&quot;&lt;font size='2' color='red'&gt;&quot;+username+&quot;来了[&quot;+request.getRemoteAddr()+&quot;],大家欢迎!&lt;/font&gt;&lt;br&gt;&quot
;<br>
getServletContext().setAttribute(&quot;chat1Msg&quot;,tempmsg);<br>
<br>
<br>
//输出欢迎页面<br>
out.println(&quot;&lt;p align='center'&gt;&lt;font color='#8080FF'&gt;未名聊天室1&lt;/font&gt;&lt;/p&gt;&quot
;<br>
out.println(&quot;&lt;hr width='80%' color='#0000FF'&gt;&quot
;<br>
out.println(&quot;&lt;div align='center'&gt;&lt;center&gt;&quot
;<br>
out.println(&quot;&lt;table border='0' width='86%' height='233'&gt;&quot
;<br>
out.println(&quot;&lt;tr&gt;&quot
;<br>
out.println(&quot;&lt;td width='4%' height='23'&gt;&lt;img src='new.gif' width='20'
height='20'&quot
;<br>
out.println(&quot;alt='new.gif (970 bytes)'&gt;&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;td width='96%' height='23' bgcolor='#B5B5FF'&gt;各位聊客,欢迎使用本聊天室,本聊天室支持人数无上限,每隔10秒刷新消息队列,每隔&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;/tr&gt;&quot
;<br>
out.println(&quot;&lt;tr&gt;&quot
;-<br>
out.println(&quot;&lt;td width='4%' height='13'&gt;&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;td width='96%' height='13' bgcolor='#B5B5FF'&gt;两分钟刷新用户列表,如果用户在四分钟内没有任何动作的话,那么此用户将被注销.&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;/tr&gt;&quot
;<br>
out.println(&quot;&lt;tr&gt;&quot
;<br>
out.println(&quot;&lt;td width='4%' height='11'&gt;&lt;img src='new.gif' width='20'
height='20'&quot
;<br>
out.println(&quot;alt='new.gif (970 bytes)'&gt;&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;td width='96%' height='11' bgcolor='#CACAFF'&gt;本聊天室支持34种动作,31种表情,悄悄话等功能,今后将加入图形化功能,及跳转功能,&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;/tr&gt;&quot
;<br>
out.println(&quot;&lt;tr&gt;&quot
;<br>
out.println(&quot;&lt;td width='4%' height='7'&gt;&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;td width='96%' height='7' bgcolor='#CACAFF'&gt;新建聊天室等功能.&lt;/td&gt;&quot
;<br>
out.println(&quot;
&lt;/tr&gt;&quot
;<br>
out.println(&quot;&lt;tr&gt;&quot
;<br>
out.println(&quot;&lt;td width='4%' height='19'&gt;&lt;img src='new.gif' width='20'
height='20'&quot
;<br>
out.println(&quot;alt='new.gif (970 bytes)'&gt;&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;td width='96%' height='19' bgcolor='#D2D2FF'&gt;如果你要离开本聊天室,请点击右边窗口内的&amp;quot;关闭&amp;quot;.&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;/tr&gt;&quot
;<br>
out.println(&quot;&lt;tr&gt;&quot
;<br>
out.println(&quot;&lt;td width='4%' height='20'&gt;&lt;img src='new.gif' width='20'
height='20'&quot
;<br>
out.println(&quot;alt='new.gif (970 bytes)'&gt;&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;td width='96%' height='20' bgcolor='#EEEEFF'&gt;如果您有什么批评及建议,请到&amp;quot;三角地&amp;quot;发表文章.&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;/tr&gt;&quot
;<br>
out.println(&quot;&lt;tr&gt;&quot
;<br>
out.println(&quot;&lt;td width='4%' height='22'&gt;&lt;img src='new.gif' width='20'
height='20'&quot
;<br>
out.println(&quot;alt='new.gif (970 bytes)'&gt;&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;td width='96%' height='22' bgcolor='#F4F4FF'&gt;请不要在本聊天室内发表反动言论及对他人进行人身攻击.&lt;/td&gt;&quot
;<br>
out.println(&quot;&lt;/tr&gt;&quot
;<br>
out.println(&quot;&lt;/table&gt;&quot
;<br>
out.println(&quot;&lt;/center&gt;&lt;/div&gt;&quot
;<br>
out.println(&quot;&lt;p align='center'&gt;&lt;a href='main.html' target='_top'&gt;请进&lt;/a&gt;&lt;/p&gt;&quot
;<br>
}<br>
else
<br>
{<br>
out.println(&quot;&lt;center&gt;&lt;font color='red' size='2'&gt;用户名相同&quot
;<br>
out.println(&quot;&lt;a href='login.html'&gt;重新申请ID&lt;/a&gt;&lt;/font&gt;&lt;/center&gt;&quot
;<br>
}<br>
%&gt;</p>
<p>&lt;%<br>
if (boolcanlogin==true)<br>
{<br>
//用一个哈希表来记录用户在聊天室呆的时间<br>
Hashtable userLife=(Hashtable)getServletContext().getAttribute(&quot;userLife&quot
;<br>
//用一个哈希表记录在聊用户的IP地址<br>
Hashtable userIP=(Hashtable)getServletContext().getAttribute(&quot;userIP&quot
;<br>
//取得用户登录时间<br>
Date userTime=new Date();<br>
//记录用户登录时间<br>
userLife.put((String)session.getValue(&quot;username&quot
,new Long(userTime.getTime()));<br>
//记录用户IP地址<br>
userIP.put((String)session.getValue(&quot;username&quot
,request.getRemoteAddr());<br>
getServletContext().setAttribute(&quot;userLife&quot;,userLife);<br>
getServletContext().setAttribute(&quot;userIP&quot;,userIP);<br>
}<br>
%&gt;<br>
&lt;body&gt;</p>
<p>&lt;/body&gt;<br>
&lt;/html&gt;</p>