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