chat.jsp
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:6k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. <%@ page language="java" pageEncoding="GBK"%>
  2. <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
  3. <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
  4. <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
  5. <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  7. <html:html lang="true">
  8. <head>
  9. <html:base />
  10. <title>chat.jsp</title>
  11. <script type="text/javascript" src="${pageContext.request.contextPath}/Jsp_file/chat/alai_tree.js"></script>
  12. <script type="text/javascript" src="${pageContext.request.contextPath}/Jsp_file/chat/alai_tree_cool.js"></script>
  13. <script type="text/javascript" src="${pageContext.request.contextPath}/Jsp_file/chat/alai_imagelist.js"></script>
  14. <link href="${pageContext.request.contextPath}/Css_file/oa.css" rel="stylesheet" type="text/css" />
  15. </head>
  16. <script>
  17. //建立ImageList控件,并添加相关图标
  18. var icons=new alai_imagelist()
  19. icons.path="${pageContext.request.contextPath}/Img_file/chat/";
  20. icons.type="gif";
  21. icons.add("sun.gif","default");
  22. icons.add("pisa_plus.gif","expand");
  23. icons.add("pisa_minus.gif","collapse");
  24. //send
  25. var allcontent="";
  26. var xmlHttp;
  27. var xmlHttp2;
  28. var xmlHttp3;
  29. var getter="";
  30. var uname="";
  31. var chattype;
  32. var sender="<bean:write name='uno' />";
  33. function send(){
  34. //将消息显示页面上
  35. var content =eWebEditor1.getHTML();//取得editor内容
  36. if(getter==""){
  37. alert("还没选择发送消息的对象!");
  38. }else{
  39. if(content==""){
  40. alert("不能发送空消息!");
  41. }else{
  42. var dcontent=document.getElementById("chatcontent");
  43. var d = new Date();
  44. d=d.toLocaleString();
  45. //将消息保存到数据库中
  46. xmlHttp2=createHttpRequest();
  47. var url="${pageContext.request.contextPath}/chat.do?task=save&timeStamp="
  48. +new Date().getTime()+"&date="+d+"&sender="+sender+"&getter="+getter+"&chattype="
  49. +chattype+"&content="+content;
  50. xmlHttp2.open("GET",url,true);
  51. xmlHttp2.send(null);
  52. content ="<bean:write name='uname'/>"+"&nbsp;"+d+"&nbsp;对&nbsp;"+uname+
  53. "&nbsp;说:<br>&nbsp;&nbsp;&nbsp;&nbsp;"+content+"<br>";
  54. dcontent.innerHTML=dcontent.innerHTML+content+"<br>";
  55. eWebEditor1.setHTML("");
  56. }
  57. }
  58. }
  59.  <!-- 发空消息,接受服务器端传来的数据 -->
  60. function sendnull(){
  61. xmlHttp=createHttpRequest();
  62. var url="${pageContext.request.contextPath}/chat.do?task=read";
  63. xmlHttp.open("GET",url,true);
  64. xmlHttp.onreadystatechange=callback;
  65. xmlHttp.send(null);
  66. }
  67. window.setInterval(sendnull,5000);
  68. function createHttpRequest(){
  69. var x;
  70. if (window.ActiveXObject){
  71. x = new ActiveXObject("Microsoft.XMLHTTP");
  72. }else if (window.XMLHttpRequest){
  73. x = new XMLHttpRequest();
  74. }
  75. return x;
  76. }
  77. //recive from server 
  78. function callback(){
  79. if (xmlHttp.readyState == 4){
  80. if (xmlHttp.status == 200){
  81. var text=xmlHttp.responseText;
  82. var dc=document.getElementById("chatcontent");
  83. dc.innerHTML=dc.innerHTML+text;
  84. }
  85. }
  86. }
  87. //弹出聊天记录
  88. function wopen(id){
  89. var url='${pageContext.request.contextPath}/chat.do?task=history&id='+id;
  90. 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;
  91. window.open(url,'bbb',attr);
  92. }
  93. </script>
  94. <body>
  95. <html:form action="/chat" styleId="form1">
  96. <table width="100%" height="100%" border="0" class="tr3 f_one">
  97. <tr class="tr3 f_one">
  98. <td width="80%" valign="top">
  99. &nbsp;
  100. <div id="chatcontent" style="overflow:auto;height: 200px;"></div>
  101. </td>
  102. <td rowspan="3" valign="top" class="tr3 f_two">
  103. <div id="divTree1"></div>
  104. </td>
  105. </tr>
  106. <tr class="tr3 f_two">
  107. <td valign="bottom">
  108. <html:hidden name="chatForm" property="ccontent" />
  109. <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>
  110. </td>
  111. </tr>
  112. <tr>
  113. <td align="right">
  114. <input type="button" class="btn" name="record" value=" 聊天记录 " onclick="wopen('<bean:write name='uno'/>')">
  115. <input type="button" name="submit" value=" 发送 " onclick="send();" class="btn">
  116. </td>
  117. </tr>
  118. </table>
  119. </html:form>
  120. <script>
  121. <!--
  122. var tree1=new alai_tree(icons,18,divTree1);
  123. var root=tree1.root;
  124. n_main=root.add("博洋");
  125. n_main.value="0";
  126. n_main.uname="全公司";
  127. n_main.flag="2";
  128. <logic:iterate id="dlist" name="deptlist">
  129. n_dept${dlist.did}=n_main.add("${dlist.dname}");
  130. n_dept${dlist.did}.value="${dlist.did}";
  131. n_dept${dlist.did}.uname="${dlist.dname}";
  132. n_dept${dlist.did}.flag="1";
  133. <logic:iterate id="ulist" name="userlist">
  134. if(${ulist.did}==${dlist.did}){
  135. n_user${ulist.uno}=n_dept${dlist.did}.add("${ulist.uname}");
  136. n_user${ulist.uno}.value=${ulist.uno};
  137. n_user${ulist.uno}.uname="${ulist.uname}";
  138. n_user${ulist.uno}.flag="0";
  139. <logic:iterate id="on" name="onlinelist">
  140. if(${on.userid}==${ulist.uno}){
  141. n_user${ulist.uno}.label.style.color="red";
  142. }
  143. </logic:iterate>
  144. }
  145. </logic:iterate>
  146. </logic:iterate>
  147. tree1.target="_blank";
  148. tree1.onclick=function(node)
  149. {
  150. if(node.flag=='0' && sender==node.value){
  151. alert("不能向自己发消息!");
  152. }else{
  153. chattype=node.flag;
  154. getter=node.value;
  155. uname=node.uname;
  156. }
  157. }
  158. setTimeout("flushtree()",3000);
  159. function flushtree(){
  160. xmlHttp3=createHttpRequest();
  161. var url="${pageContext.request.contextPath}/chat.do?task=online";
  162. xmlHttp3.open("GET",url,true);
  163. xmlHttp3.onreadystatechange=online;
  164. xmlHttp3.send(null);
  165. setTimeout("flushtree()",3000);
  166. }
  167. function online(){
  168. if (xmlHttp3.readyState == 4){
  169. if (xmlHttp3.status == 200){
  170. var text=xmlHttp3.responseText;
  171. var str=text.split(',');
  172. <logic:iterate id="ulist" name="userlist">
  173. for(var i=0;i<str.length;i++){
  174. if(str[i]==${ulist.uno}){
  175. n_user${ulist.uno}.label.style.color="red";
  176. }
  177. }
  178. </logic:iterate>
  179. }
  180. }
  181. }
  182. //-->
  183. </script>
  184. </body>
  185. </html:html>