📄 chat.jsp
字号:
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>chat.jsp</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/Jsp_file/chat/alai_tree.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/Jsp_file/chat/alai_tree_cool.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/Jsp_file/chat/alai_imagelist.js"></script>
<link href="${pageContext.request.contextPath}/Css_file/oa.css" rel="stylesheet" type="text/css" />
</head>
<script>
//建立ImageList控件,并添加相关图标
var icons=new alai_imagelist()
icons.path="${pageContext.request.contextPath}/Img_file/chat/";
icons.type="gif";
icons.add("sun.gif","default");
icons.add("pisa_plus.gif","expand");
icons.add("pisa_minus.gif","collapse");
//send
var allcontent="";
var xmlHttp;
var xmlHttp2;
var xmlHttp3;
var getter="";
var uname="";
var chattype;
var sender="<bean:write name='uno' />";
function send(){
//将消息显示页面上
var content =eWebEditor1.getHTML();//取得editor内容
if(getter==""){
alert("还没选择发送消息的对象!");
}else{
if(content==""){
alert("不能发送空消息!");
}else{
var dcontent=document.getElementById("chatcontent");
var d = new Date();
d=d.toLocaleString();
//将消息保存到数据库中
xmlHttp2=createHttpRequest();
var url="${pageContext.request.contextPath}/chat.do?task=save&timeStamp="
+new Date().getTime()+"&date="+d+"&sender="+sender+"&getter="+getter+"&chattype="
+chattype+"&content="+content;
xmlHttp2.open("GET",url,true);
xmlHttp2.send(null);
content ="<bean:write name='uname'/>"+" "+d+" 对 "+uname+
" 说:<br> "+content+"<br>";
dcontent.innerHTML=dcontent.innerHTML+content+"<br>";
eWebEditor1.setHTML("");
}
}
}
<!-- 发空消息,接受服务器端传来的数据 -->
function sendnull(){
xmlHttp=createHttpRequest();
var url="${pageContext.request.contextPath}/chat.do?task=read";
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=callback;
xmlHttp.send(null);
}
window.setInterval(sendnull,5000);
function createHttpRequest(){
var x;
if (window.ActiveXObject){
x = new ActiveXObject("Microsoft.XMLHTTP");
}else if (window.XMLHttpRequest){
x = new XMLHttpRequest();
}
return x;
}
//recive from server
function callback(){
if (xmlHttp.readyState == 4){
if (xmlHttp.status == 200){
var text=xmlHttp.responseText;
var dc=document.getElementById("chatcontent");
dc.innerHTML=dc.innerHTML+text;
}
}
}
//弹出聊天记录
function wopen(id){
var url='${pageContext.request.contextPath}/chat.do?task=history&id='+id;
var attr='toolbar=no location=no status=no menubar=no scrollbars=1 revisable=no width=700 Height=600 left='+(screen.width-700)/2+' top='+(screen.height-600)/2;
window.open(url,'bbb',attr);
}
</script>
<body>
<html:form action="/chat" styleId="form1">
<table width="100%" height="100%" border="0" class="tr3 f_one">
<tr class="tr3 f_one">
<td width="80%" valign="top">
<div id="chatcontent" style="overflow:auto;height: 200px;"></div>
</td>
<td rowspan="3" valign="top" class="tr3 f_two">
<div id="divTree1"></div>
</td>
</tr>
<tr class="tr3 f_two">
<td valign="bottom">
<html:hidden name="chatForm" property="ccontent" />
<iframe ID="eWebEditor1" src="${pageContext.request.contextPath}/editor2/ewebeditor.htm?id=content&style=coolblue&extcss=${pageContext.request.contextPath}/Css_file/oa.css" frameborder="0" scrolling="no" width="100%" height="250"></iframe>
</td>
</tr>
<tr>
<td align="right">
<input type="button" class="btn" name="record" value=" 聊天记录 " onclick="wopen('<bean:write name='uno'/>')">
<input type="button" name="submit" value=" 发送 " onclick="send();" class="btn">
</td>
</tr>
</table>
</html:form>
<script>
<!--
var tree1=new alai_tree(icons,18,divTree1);
var root=tree1.root;
n_main=root.add("博洋");
n_main.value="0";
n_main.uname="全公司";
n_main.flag="2";
<logic:iterate id="dlist" name="deptlist">
n_dept${dlist.did}=n_main.add("${dlist.dname}");
n_dept${dlist.did}.value="${dlist.did}";
n_dept${dlist.did}.uname="${dlist.dname}";
n_dept${dlist.did}.flag="1";
<logic:iterate id="ulist" name="userlist">
if(${ulist.did}==${dlist.did}){
n_user${ulist.uno}=n_dept${dlist.did}.add("${ulist.uname}");
n_user${ulist.uno}.value=${ulist.uno};
n_user${ulist.uno}.uname="${ulist.uname}";
n_user${ulist.uno}.flag="0";
<logic:iterate id="on" name="onlinelist">
if(${on.userid}==${ulist.uno}){
n_user${ulist.uno}.label.style.color="red";
}
</logic:iterate>
}
</logic:iterate>
</logic:iterate>
tree1.target="_blank";
tree1.onclick=function(node)
{
if(node.flag=='0' && sender==node.value){
alert("不能向自己发消息!");
}else{
chattype=node.flag;
getter=node.value;
uname=node.uname;
}
}
setTimeout("flushtree()",3000);
function flushtree(){
xmlHttp3=createHttpRequest();
var url="${pageContext.request.contextPath}/chat.do?task=online";
xmlHttp3.open("GET",url,true);
xmlHttp3.onreadystatechange=online;
xmlHttp3.send(null);
setTimeout("flushtree()",3000);
}
function online(){
if (xmlHttp3.readyState == 4){
if (xmlHttp3.status == 200){
var text=xmlHttp3.responseText;
var str=text.split(',');
<logic:iterate id="ulist" name="userlist">
for(var i=0;i<str.length;i++){
if(str[i]==${ulist.uno}){
n_user${ulist.uno}.label.style.color="red";
}
}
</logic:iterate>
}
}
}
//-->
</script>
</body>
</html:html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -