📄 main.jsp
字号:
<%@ page import="java.util.*" %>
<%@ include file="static.jsp"%>
<%--riso.mybook.jsp.c7.userBean用于存储用户信息--%>
<jsp:useBean id="user" class="riso.mybook.jsp.c7.userBean" scope="session"/>
<%--riso.mybook.jsp.c7.userList用于存储在线用户列表--%>
<jsp:useBean id="userlist" class="riso.mybook.jsp.c7.userList" scope="application"/>
<%--riso.mybook.jsp.c7.chat用于存储用户聊天信息--%>
<jsp:useBean id="chat" class="riso.mybook.jsp.c7.chat" scope="application"/>
<%
//刷新在线用户列表,踢出超时用户
userList.removeOverdue();
String userName,chatUserName,job,chatWords,aim,color;
//得到并处理发出消息的用户名
userName=user.gerUserName();
if (userName == null) {
response.sendRedirect("login.html");
}
userName = userName.trim();
if (!(userlist.isUserOnline(userName))) {
response.sendRedirect("login,html");
}
%>
<html>
<head>
<title> List </title>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<meta http-equiv="refresh" content="10" url="refresh.jsp">
</head>
<%
job = request.getParameter("job");
//用户发出聊天信息的情况
if (!(job==null)) {
if (job.equals("input")) {
//获得用户发出的聊天信息
chatWords = request.getParameter("chatWords");
aim = request.getParameter("aim");
color = request.getParameter("color");
//设定缺省值
if (chatWords==null) {
chatWords = "";
}
if (aim==null) {
aim = ALLUSER;
}
if (color == null) {
color = "black";
}
//除去聊天信息中无效的空格(前后的空格)
chatWords = chatWords.trim();
aim = aim.trim();
color = color.trim();
//将颜色信息加入到聊天信息中
chatWords = "<font color="+color+">"+chatWords+"</font>";
//当消息的接受者已经离开后,向消息的发出者输出特定的消息
if ((userList.isUserOnLine(aim))||(aim.equals(ALLUSER))) {
chat.setChat(userName,chatWords,aim);
}
else {
chatWords= "用户" + aim + "已离开";
chat.setChat("系统",chatWords,userName);
}
//更新用户最后操作时间
userList.updateUser(userName);
}
}
//取出所有消息
Enumeration vt1= chat.getChat();
while (vt1.hasMoreElements()) {
String strOut = "";
LinkedList ci =(LinkedList)vt1.nextElement();
chatUserName = (String)ci.get(0);
chatWords = (String)ci.get(1);
aim = (String)ci.get(2);
//对于消息的接受者为特定用户时
//只有消息的发出者和接受者能看到消息
//对于消息的接受者为"*",即全体用户时
//所有的用户都可看见
if (aim.equals(ALLUSER)) {
strOut = "<font color=red>" + chatName + "</font> 说道:" + chatWords;
out.println(strOut);
out.println("<br>");
}
else {
if ((userName.equals(aim))||(userName.equals(chatUserName))) {
strOut = "<font color=red>" + chatUserName + "</font> 对 ";
strOut = strOut + aim + "说道 : " + chatWords;
out.println(strOut);
out.println("<br>");
}
}
}
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -