📄 11-3.txt
字号:
<%--首先从session对象中获取用户的id,如果id不存在说明用户非正常登录,
程序将提示用户先进行登录--%>
<%
String chatid=new String();
chatid=(String)session.getValue("chatid");
if(chatid==null){
%>
用户不存在,请先登录。
<%
}else{
String isin=new String();
isin=(String)session.getValue("chatroom");
%>
<%--isin为null则说明用户还没有进入过聊天室,
否则为未正常退出又重复进入,需要跳过一些处理--%>
<%
if(isin==null){
%>
<%-- 用户进入某一个聊天室,这个聊天室的人数应该加1
修改application对象中保存这个参数的变量数值--%>
<%
String chatroom=new String();
chatroom=request.getParameter("chatroom");
chatroom="room"+chatroom;
int num;
String numtemp=new String();
String temp=new String();
temp=chatroom+"usernum";
numtemp=(String)application.getAttribute(temp);
num=Integer.parseInt(numtemp);
num=num+1;
numtemp=numtemp.valueOf(num);
application.setAttribute(temp,numtemp);
%>
<%--用application对象的变量保存这个用户的id,
以便判断以后登录用户的id是否合法 --%>
<%
temp=chatroom+"user"+numtemp;
application.setAttribute(temp,chatid);
session.putValue("chatroom",chatroom);
%>
<%-- 设定该用户的聊天刷新时间和在线用户刷新时间--%>
<%
session.putValue("retime1","10");
session.putValue("retime2","10");
%>
<%--将用户登录的消息加入到application变量用于保存聊天信息的一组变量中
因为某个用户进人聊天室要每个聊天用户一个信息
首先要设定当前最新信息的指针chatpoint加 1 --%>
<%
temp=chatroom+"chatpoint";
String chatpoint=new String();
chatpoint=(String)application.getAttribute(temp);
if(chatpoint==null){
chatpoint="0";
}
int chatpointn;
chatpointn=Integer.parseInt(chatpoint);
chatpointn=chatpointn+1;
%>
<%-- 如果指针指向超过30,则从1开始,覆盖掉旧的信息 --%>
<%
if(chatpointn==31){
chatpointn=1;
}
chatpoint=chatpoint.valueOf(chatpointn);
temp=chatroom+"chatpoint";
application.setAttribute(temp,chatpoint);
temp=chatroom+"chatword"+chatpoint;
%>
<%--
分别保存这个系统信息的内容、显示颜色,
设私聊标志为no,说明每个用户都可以看到这个信息--%>
<%
application.setAttribute(temp,chatid);
temp=chatroom+"chatcolor"+chatpoint;
application.setAttribute(temp,"red");
temp=chatroom+"chatprivate"+chatpoint;
application.setAttribute(temp,"no");
}
%>
<html>
<head>
<title>聊天室</title>
<meta http-equiv="Content-Type" content="text/html";charset=gb2312">
</head>
<%--下面是框架结构,注意在chat.jsp后要加上"?isret",后面再详细讲解其用途--%>
<frameset rows="415,111" frameborder="YES" border="1" framespacing="1" cols="*">
<frameset cols="623,160" frameborder="YES" border="1" frmespacing="1" rows="*">
<frame name="chat" src="chat.jsp?isret=yes">
<frame name="user" scrolling="NO" noresize src="user.jsp">
</frameset>
<frame name="manage" scrolling="NO" noresize src="manage.jsp">
</frameset>
<noframes>
<body bgcolor="#FFFFFF">
</body>
</noframes>
</html>
<%
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -