📄 chatroom.jsp
字号:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript">
var xmlHttp = false;
var xmlHttp1 = false;
function createXmlHttp(){
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function createXmlHttp1(){
if (window.ActiveXObject) {
xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
}else if (window.XMLHttpRequest) {
xmlHttp1 = new XMLHttpRequest();
}
}
function getChat(){
//创建xmlhttprequest
createXmlHttp();
var url = "ChatDO?chat="+document.getElementById("chat").value+"&isPrivate="+document.getElementById("isPrivate").checked+"&user2="+document.getElementById("names").value;
xmlHttp.open("get",url);
xmlHttp.send(null);
}
function renew(){
createXmlHttp();
var url="GetChatDO?time="+new Date();
xmlHttp.onreadystatechange=showPublicChat;
xmlHttp.open("get",url);
xmlHttp.send(null);
}
function showPublicChat(){
if(xmlHttp.readyState==4 && xmlHttp.status==200){
//1.取得服务器响应内容
var publicChat = xmlHttp.responseText;
//2.动态修改页面的部份内容
document.getElementById("publicChat").innerHTML =publicChat;
}
}
function renewPrivateChat(){
createXmlHttp1();
var url="GetPrivateChatDO?time="+new Date();
xmlHttp1.onreadystatechange=showPrivteChat;
xmlHttp1.open("get",url);
xmlHttp1.send(null);
}
function showPrivteChat(){
if(xmlHttp1.readyState==4 && xmlHttp1.status==200){
//1.取得服务器响应内容
var privateChat = xmlHttp1.responseText;
//2.动态修改页面的部份内容
document.getElementById("privateChat").innerHTML =privateChat;
}
}
</script>
<script type="text/javascript">
setInterval("renew()",1000);
</script>
<script type="text/javascript">
setInterval("renewPrivateChat()",1000);
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"/>
<title>聊天室</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" rev="stylesheet" href="css/block.css" />
</head>
<body>
<div id="rightWraper">
<div class="text"> 欢迎${sessionScope.user.name}登陆${sessionScope.chatroomName}聊天室 <br><hr>
<label id="publicChat"></label>
<hr>
<label id="privateChat"></label>
<hr>
<form id="myform" name="myform" action="ChatDO?name=${param.name}" method="post">
在线用户
<%
String chatroomName = (String)session.getAttribute("chatroomName");
%>
<select id="names" name="names">
<c:forEach items="<%=application.getAttribute(chatroomName+"loginChatroomUserList") %>" var="name">
<option value="${name}">${name}</option>
</c:forEach>
</select>
<input type="checkbox" id="isPrivate" name="isPrivate" />私聊<br>
<input type="text" id="chat" name="chat" size="25"/>
<input type="button" value="发言" onclick="getChat();"/>
</form>
</div>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -