- 浏览: 241213 次
- 性别:
- 来自: 浙江科技学院
文章分类
最新评论
-
浅浅陌上桑:
为什么最后一个是不完整的
JSP+AJAX 聊天室代码 -
juedi:
很好
StringTokenizer类的使用方法 -
sungine:
正则是很给力只是用起来很别扭StringTokenizer 是 ...
StringTokenizer类的使用方法 -
songjiesdnu:
chxiaowu 写道 StringTokenizer 是出于 ...
StringTokenizer类的使用方法 -
songjiesdnu:
chxiaowu 写道 StringTokenizer 是出于 ...
StringTokenizer类的使用方法
tw-sack.js
display.js
chat.js
chat.jsp
index.html
js 代码
- /* Simple AJAX Code-Kit (SACK) */
- /* 2005 Gregory Wild-Smith */
- /* [url]www.twilightuniverse.com[/url] */
- /* Software licenced under a modified X11 licence, see documentation or authors website for more details */
- function sack(file){
- this.AjaxFailedAlert = "Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n";
- this.requestFile = file; // 提交的页面
- this.method = "POST";
- this.URLString = "";
- this.encodeURIString = true;
- this.execute = false;
- this.onLoading = function() { };//读取中
- this.onLoaded = function() { };//已经读取
- this.onInteractive = function() { };//交互中
- this.onCompletion = function() { }; // 信息返回之后执行的方法
- this.complete = function(){};//处理完毕
- this.createAJAX = function() {
- try {
- this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (e) {
- try {
- this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (err) {
- this.xmlhttp = null;
- }
- }
- if(!this.xmlhttp && typeof XMLHttpRequest != "undefined")
- this.xmlhttp = new XMLHttpRequest();
- if (!this.xmlhttp){
- this.failed = true;
- }
- };
- this.setVar = function(name, value){
- if (this.URLString.length < 3){
- this.URLString = name + "=" + value;
- } else {
- this.URLString += "&" + name + "=" + value;
- }
- }
- this.encVar = function(name, value){
- var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
- return varString;
- }
- this.encodeURLString = function(string){
- varArray = string.split('&');
- for (i = 0; i < varArray.length; i++){
- urlVars = varArray[i].split('=');
- if (urlVars[0].indexOf('amp;') != -1){
- urlVars[0] = urlVars[0].substring(4);
- }
- varArray[i] = this.encVar(urlVars[0],urlVars[1]);
- }
- return varArray.join('&');
- }
- this.runResponse = function(){
- eval(this.response);
- }
- this.runAJAX = function(urlstring){
- this.responseStatus = new Array(2);
- if(this.failed && this.AjaxFailedAlert){
- alert(this.AjaxFailedAlert);
- } else {
- if (urlstring){
- if (this.URLString.length){
- this.URLString = this.URLString + "&" + urlstring;
- } else {
- this.URLString = urlstring;
- }
- }
- if (this.encodeURIString){
- var timeval = new Date().getTime();
- this.URLString = this.encodeURLString(this.URLString);
- this.setVar("rndval", timeval);
- }
- if (this.element) { this.elementObj = document.getElementById(this.element); }
- if (this.xmlhttp) {
- var self = this;
- if (this.method == "GET") {
- var totalurlstring = this.requestFile + "?" + this.URLString;
- this.xmlhttp.open(this.method, totalurlstring, true);
- } else {
- this.xmlhttp.open(this.method, this.requestFile, true);
- }
- if (this.method == "POST"){
- try {
- this.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8')
- } catch (e) {}
- }
- this.xmlhttp.send(this.URLString);
- this.xmlhttp.onreadystatechange = function() {
- switch (self.xmlhttp.readyState){
- case 1: //读取中
- self.onLoading();
- break;
- case 2: //已经读取
- self.onLoaded();
- break;
- case 3: //交互中
- self.onInteractive();
- break;
- case 4: //处理完毕
- self.response = self.xmlhttp.responseText;
- self.responseXML = self.xmlhttp.responseXML;
- self.responseStatus[0] = self.xmlhttp.status;
- self.responseStatus[1] = self.xmlhttp.statusText;
- self.onCompletion();
- if(self.execute){ self.runResponse(); }
- if (self.elementObj) {
- var elemNodeName = self.elementObj.nodeName;
- elemNodeName.toLowerCase();
- if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea"){
- self.elementObj.value = self.response;
- } else {
- self.elementObj.innerHTML = self.response;
- }
- }
- self.URLString = "";
- self.complete();
- break;
- }
- };
- }
- }
- };
- this.createAJAX();
- }
display.js
js 代码
- function overInput(a){
- getId("btn").style.border = "1px solid #54ce43"
- getId("content").style.border = "1px solid #54ce43"
- focs()
- }
- function outInput(a){
- getId("btn").style.border = "1px solid #AAA"
- getId("content").style.border = "1px solid #AAA"
- focs()
- }
- function overBtn(a){
- a.src = "images/hover.gif"
- }
- function outBtn(a){
- a.src = "images/rest.gif"
- }
- function lrover(a){
- a.style.backgroundColor = "#EEE"
- }
- function lrout(a){
- a.style.backgroundColor = "#FFF"
- }
- function focs(){
- getName("content").focus();
- }
- function clean(){
- getName("content").value = ""
- }
- var chats = new Array()
- var chatStart
- function addChat(strChat){
- if(chats.length > 199){
- chats.shift()
- }
- chats.push(strChat)
- chatStart = chats.length
- }
- function preChat(){
- if(chatStart && chatStart >= 1){
- if(chatStart == 1){
- getName("content").value = chats[0]
- chatStart = 0.5
- }else{
- chatStart -= 1
- getName("content").value = chats[chatStart]
- }
- }
- getId("loadifo").innerHTML = chatStart+","+chats.length
- }
- function nextChat(){
- if(chatStart && chatStart < chats.length && chats.length > 1){
- if(chatStart == 0.5){
- chatStart = 1
- }else if(chatStart == chats.length - 1){
- chatStart = chats.length - 1
- }else{
- chatStart += 1
- }
- getName("content").value = chats[chatStart]
- }
- getId("loadifo").innerHTML = chatStart+","+chats.length
- }
- window.onload = function(){
- getId("outs").onmousedown = function(){
- overs = 1
- }
- getId("outs").onmouseout = function(){
- overs = 0
- focs()
- }
- getName("content").onkeydown = function(e){
- if(document.all){
- var Keys = event.keyCode;
- }else{
- var Keys = e.which;
- }
- //alert(Keys)
- if(Keys == "38"){
- preChat()
- }else if(Keys == "40"){
- nextChat()
- }else if(event.ctrlKey && Keys == "13"){
- doUsingPost()
- }else if(event.ctrlKey && Keys == "46"){
- clean()
- }
- }
- }
- function getId(objId){
- return document.getElementById(objId)
- }
- function getName(objName){
- return document.getElementsByName(objName)[0]
- }
chat.js
js 代码
- var overs;
- var clien = 0;
- function doUsingGet(){
- var ajax=new sack("chat.jsp");
- ajax.setVar("clien",clien);
- ajax.setVar("timeStamp",new Date().getTime());
- ajax.method='GET';
- ajax.onLoading=function(){
- document.getElementById("zt").innerHTML="读取中......";
- }
- ajax.onCompletion=function(){// 信息返回之后执行的方法
- CheckState(ajax.responseXML.documentElement);
- }
- ajax.onLoaded=function(){
- document.getElementById("zt").innerHTML="已经读取......";
- }
- ajax.onInteractive=function(){
- document.getElementById("zt").innerHTML="交互中......";
- }
- ajax.complete = function(){
- document.getElementById("zt").innerHTML="处理完毕......";
- }
- ajax.runAJAX();
- }
- function doUsingPost(){
- if(getName("content").value!=""){
- var named = getName("named").value;
- var content = getName("content").value;
- var ajax=new sack("chat.jsp");
- ajax.setVar("clien",clien);
- ajax.setVar("content",content);
- ajax.setVar("named",named);
- ajax.setVar("timeStamp",new Date().getTime());
- ajax.method='POST';
- ajax.onLoading=function(){
- document.getElementById("zt").innerHTML="读取中......";
- }
- ajax.onCompletion=function(){// 信息返回之后执行的方法
- CheckState(ajax.responseXML.documentElement);
- }
- ajax.onLoaded=function(){
- document.getElementById("zt").innerHTML="已经读取......";
- }
- ajax.onInteractive=function(){
- document.getElementById("zt").innerHTML="交互中......";
- }
- ajax.complete = function(){
- document.getElementById("zt").innerHTML="处理完毕......";
- }
- ajax.runAJAX();
- focs();
- clean();
- }else{
- alert("请输入对话内容!")
- focs()
- }
- }
- function CheckState(res){
- var resLen = res.getElementsByTagName("items").length
- if(getTag(res,0,"num") != clien){
- clien = getTag(res,0,"num")
- for(var i=0; i<resLen; i++){
- var useName = getTag(res,i,"name")
- var useMag = getTag(res,i,"conts")
- var useIp = getTag(res,i,"ip")
- if(clien != "0" && useMag != ""){
- if(useName != ""){
- var lis = "用户"+ useName + "说:" + useMag //+ " ["+ useIp + "]"
- }else{
- var lis = "用户 ["+ useIp + "] 说:" + useMag
- }
- }else{
- var lis = ""
- }
- getId("chatmain").innerHTML += lis + "<br />"
- }
- innerSize()
- }
- }
- function innerSize(){
- if(overs != 1){
- if(getId("chatmain").offsetHeight < getId("outmain").offsetHeight){
- getId("chatmain").style.marginTop = getId("outmain").offsetHeight - getId("chatmain").offsetHeight +"px";
- }else{
- getId("chatmain").scrollIntoView(false)
- }
- }
- }
- function getTag(response,i,objTagName){
- try{
- var nodeV = response.getElementsByTagName(objTagName)[i].firstChild.nodeValue;
- }catch(e){
- var nodeV = ""
- }
- return nodeV;
- }
- setInterval("doUsingGet()",1000)
chat.jsp
jsp代码
- <%@ page contentType="text/xml; charset=gb2312" %>
- <%!
- String func(String content){
- return content.replaceAll("<","<").replaceAll(">",">");
- }
- %>
- <%
- String ip=request.getRemoteAddr(); //客户端IP
- int clien = new Integer(request.getParameter("clien")).intValue(); //当前是第几个用户 如果为0就是新来的用户
- if(application.getAttribute("counts")==null){
- application.setAttribute("counts",new Integer(0));
- }
- int counts = new Integer(application.getAttribute("counts").toString()).intValue(); //当前用户的ID
- if(request.getParameter("content")!=null){
- synchronized(this){
- if(counts < 21){
- int i = counts + 1;
- application.setAttribute("counts",new Integer(i));
- }else if(counts >= 21){
- application.setAttribute("counts","1");
- }
- counts = new Integer(application.getAttribute("counts").toString()).intValue(); //当前用户的ID
- int Cnum = counts;
- String names;
- String Msgs = request.getParameter("content");
- // Msgs=new String(Msgs.getBytes("iso8859-1"),"gb2312");
- application.setAttribute("ips" + Cnum,ip) ;
- application.setAttribute("msgs" + Cnum,func(Msgs)) ;
- if(request.getParameterValues("content") != null){
- names = request.getParameter("named");
- }else{
- names = "";
- }
- application.setAttribute("names" + Cnum,names +"") ;
- }
- }
- %><?xml version="1.0" encoding="gb2312" ?>
- <ppl>
- <num><%=application.getAttribute("counts")%></num>
- <%
- if(clien == 0){
- %>
- <items>
- <ip><%=ip%></ip>
- </items>
- <%
- }else if(clien < counts){
- for(int i=clien; i<counts; i++){
- int s = i+1;
- String useName = (String)application.getAttribute("names" + s);
- String useMsg = (String)application.getAttribute("msgs" + s);
- String useIp = (String)application.getAttribute("ips" + s);
- %>
- <items>
- <aaa><%=clien%> <%=s%></aaa>
- <bbb><%=counts%></bbb>
- <name><%=useName%></name>
- <conts><%=useMsg%></conts>
- <ip><%=useIp%></ip>
- </items>
- <%
- }
- }else if(clien > counts){
- for(int i=clien; i<21; i++){
- String useName = (String)application.getAttribute("names" + i);
- String useMsg = (String)application.getAttribute("msgs" + i);
- String useIp = (String)application.getAttribute("ips" + i);
- %>
- <items>
- <name><%=useName%></name>
- <conts><%=useMsg%></conts>
- <ip><%=useIp%></ip>
- </items>
- <%
- }
- for(int m=1; m<=counts; m++){
- String useNameM = (String)application.getAttribute("names" + m);
- String useMsgM = (String)application.getAttribute("msgs" + m);
- String useIpM = (String)application.getAttribute("ips" + m);
- %>
- <items>
- <name><%=useNameM%></name>
- <conts><%=useMsgM%></conts>
- <ip><%=useIpM%></ip>
- </items>
- <%
- }
- }else if(clien == counts){
- }
- %>
- </ppl>
index.html
html 代码
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title></title>
- <link href="images/chatstyle.css" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="js/display.js"></script>
- <script type="text/javascript" src="js/chat.js"></script>
- <script type="text/javascript" src="js/tw-sack.js"></script>
- </head>
- <body>
- <div id="zt"></div>
- <div id="loadifo"></div>
- <div id="outs"><div id="outmain"><div id="chatmain"></div></div></div>
- <div class="in">昵称:
评论
2 楼
浅浅陌上桑
2016-04-14
为什么最后一个是不完整的
1 楼
lijianbin
2007-07-16
<strong><span style="COLOR: #ff0000">tw-sack.js</span></strong><br />
<div class="code_title">js 代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-c">
<li class="alt"><span><span class="comment">/* Simple AJAX Code-Kit (SACK) */</span><span> </span></span></li>
<li class=""><span></span><span class="comment">/* 2005 Gregory Wild-Smith */</span><span> </span></li>
<li class="alt"><span></span><span class="comment">/* www.twilightuniverse.com */</span><span> </span></li>
<li class=""><span></span><span class="comment">/* Software licenced under a modified X11 licence, see documentation or authors website for more details */</span><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">function</span><span> sack(file){ </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.AjaxFailedAlert = </span><span class="string">"Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n"</span><span>; </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.requestFile = file; </span><span class="comment">// 提交的页面 </span><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.method = </span><span class="string">"POST"</span><span>; </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString = </span><span class="string">""</span><span>; </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.encodeURIString = </span><span class="keyword">true</span><span>; </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.execute = </span><span class="keyword">false</span><span>; </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.onLoading = </span><span class="keyword">function</span><span>() { };</span><span class="comment">//读取中 </span><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.onLoaded = </span><span class="keyword">function</span><span>() { };</span><span class="comment">//已经读取 </span><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.onInteractive = </span><span class="keyword">function</span><span>() { };</span><span class="comment">//交互中 </span><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.onCompletion = </span><span class="keyword">function</span><span>() { }; </span><span class="comment">// 信息返回之后执行的方法 </span><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.complete = </span><span class="keyword">function</span><span>(){};</span><span class="comment">//处理完毕 </span><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.createAJAX = </span><span class="keyword">function</span><span>() { </span></li>
<li class=""><span></span><span class="keyword">try</span><span> { </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp = </span><span class="keyword">new</span><span> ActiveXObject(</span><span class="string">"Microsoft.XMLHTTP"</span><span>); </span></li>
<li class=""><span>} </span><span class="keyword">catch</span><span> (e) { </span></li>
<li class="alt"><span></span><span class="keyword">try</span><span> { </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.xmlhttp = </span><span class="keyword">new</span><span> ActiveXObject(</span><span class="string">"Msxml2.XMLHTTP"</span><span>); </span></li>
<li class="alt"><span>} </span><span class="keyword">catch</span><span> (err) { </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.xmlhttp = </span><span class="keyword">null</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(!</span><span class="keyword">this</span><span>.xmlhttp && </span><span class="keyword">typeof</span><span> XMLHttpRequest != </span><span class="string">"undefined"</span><span>) </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.xmlhttp = </span><span class="keyword">new</span><span> XMLHttpRequest(); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (!</span><span class="keyword">this</span><span>.xmlhttp){ </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.failed = </span><span class="keyword">true</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>}; </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.setVar = </span><span class="keyword">function</span><span>(name, value){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.URLString.length < 3){ </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString = name + </span><span class="string">"="</span><span> + value; </span></li>
<li class="alt"><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString += </span><span class="string">"&"</span><span> + name + </span><span class="string">"="</span><span> + value; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.encVar = </span><span class="keyword">function</span><span>(name, value){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> varString = encodeURIComponent(name) + </span><span class="string">"="</span><span> + encodeURIComponent(value); </span></li>
<li class=""><span></span><span class="keyword">return</span><span> varString; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.encodeURLString = </span><span class="keyword">function</span><span>(string){ </span></li>
<li class=""><span>varArray = string.split('&'); </span></li>
<li class="alt"><span></span><span class="keyword">for</span><span> (i = 0; i < varArray.length; i++){ </span></li>
<li class=""><span>urlVars = varArray[i].split('='); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (urlVars[0].indexOf('amp;') != -1){ </span></li>
<li class=""><span>urlVars[0] = urlVars[0].substring(4); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>varArray[i] = </span><span class="keyword">this</span><span>.encVar(urlVars[0],urlVars[1]); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">return</span><span> varArray.join('&'); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.runResponse = </span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>eval(</span><span class="keyword">this</span><span>.response); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.runAJAX = </span><span class="keyword">function</span><span>(urlstring){ </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.responseStatus = </span><span class="keyword">new</span><span> Array(2); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(</span><span class="keyword">this</span><span>.failed && </span><span class="keyword">this</span><span>.AjaxFailedAlert){ </span></li>
<li class=""><span>alert(</span><span class="keyword">this</span><span>.AjaxFailedAlert); </span></li>
<li class="alt"><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class=""><span></span><span class="keyword">if</span><span> (urlstring){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.URLString.length){ </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString = </span><span class="keyword">this</span><span>.URLString + </span><span class="string">"&"</span><span> + urlstring; </span></li>
<li class="alt"><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString = urlstring; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.encodeURIString){ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> timeval = </span><span class="keyword">new</span><span> Date().getTime(); </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.URLString = </span><span class="keyword">this</span><span>.encodeURLString(</span><span class="keyword">this</span><span>.URLString); </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.setVar(</span><span class="string">"rndval"</span><span>, timeval); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.element) { </span><span class="keyword">this</span><span>.elementObj = document.getElementById(</span><span class="keyword">this</span><span>.element); } </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.xmlhttp) { </span></li>
<li class=""><span></span><span class="keyword">var</span><span> self = </span><span class="keyword">this</span><span>; </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.method == </span><span class="string">"GET"</span><span>) { </span></li>
<li class=""><span></span><span class="keyword">var</span><span> totalurlstring = </span><span class="keyword">this</span><span>.requestFile + </span><span class="string">"?"</span><span> + </span><span class="keyword">this</span><span>.URLString; </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp.open(</span><span class="keyword">this</span><span>.method, totalurlstring, </span><span class="keyword">true</span><span>); </span></li>
<li class=""><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp.open(</span><span class="keyword">this</span><span>.method, </span><span class="keyword">this</span><span>.requestFile, </span><span class="keyword">true</span><span>); </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.method == </span><span class="string">"POST"</span><span>){ </span></li>
<li class=""><span></span><span class="keyword">try</span><span> { </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8') </span></li>
<li class=""><span>} </span><span class="keyword">catch</span><span> (e) {} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp.send(</span><span class="keyword">this</span><span>.URLString); </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.xmlhttp.onreadystatechange = </span><span class="keyword">function</span><span>() { </span></li>
<li class="alt"><span></span><span class="keyword">switch</span><span> (self.xmlhttp.readyState){ </span></li>
<li class=""><span></span><span class="keyword">case</span><span> 1: </span><span class="comment">//读取中 </span><span> </span></li>
<li class="alt"><span>self.onLoading(); </span></li>
<li class=""><span></span><span class="keyword">break</span><span>; </span></li>
<li class="alt"><span></span><span class="keyword">case</span><span> 2: </span><span class="comment">//已经读取 </span><span> </span></li>
<li class=""><span>self.onLoaded(); </span></li>
<li class="alt"><span></span><span class="keyword">break</span><span>; </span></li>
<li class=""><span></span><span class="keyword">case</span><span> 3: </span><span class="comment">//交互中 </span><span> </span></li>
<li class="alt"><span>self.onInteractive(); </span></li>
<li class=""><span></span><span class="keyword">break</span><span>; </span></li>
<li class="alt"><span></span><span class="keyword">case</span><span> 4: </span><span class="comment">//处理完毕 </span><span> </span></li>
<li class=""><span>self.response = self.xmlhttp.responseText; </span></li>
<li class="alt"><span>self.responseXML = self.xmlhttp.responseXML; </span></li>
<li class=""><span>self.responseStatus[0] = self.xmlhttp.status; </span></li>
<li class="alt"><span>self.responseStatus[1] = self.xmlhttp.statusText; </span></li>
<li class=""><span>self.onCompletion(); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(self.execute){ self.runResponse(); } </span></li>
<li class=""><span></span><span class="keyword">if</span><span> (self.elementObj) { </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> elemNodeName = self.elementObj.nodeName; </span></li>
<li class=""><span>elemNodeName.toLowerCase(); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (elemNodeName == </span><span class="string">"input"</span><span> || elemNodeName == </span><span class="string">"select"</span><span> || elemNodeName == </span><span class="string">"option"</span><span> || elemNodeName == </span><span class="string">"textarea"</span><span>){ </span></li>
<li class=""><span>self.elementObj.value = self.response; </span></li>
<li class="alt"><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class=""><span>self.elementObj.innerHTML = self.response; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>self.URLString = </span><span class="string">""</span><span>; </span></li>
<li class=""><span>self.complete(); </span></li>
<li class="alt"><span></span><span class="keyword">break</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>}; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>}; </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.createAJAX(); </span></li>
<li class=""><span>} </span></li>
</ol>
</div>
<br />
<strong><span style="COLOR: #ff0000">display.js</span></strong><br />
<div class="code_title">js 代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-c">
<li class="alt"><span><span class="keyword">function</span><span> overInput(a){ </span></span></li>
<li class=""><span>getId(</span><span class="string">"btn"</span><span>).style.border = </span><span class="string">"1px solid #54ce43"</span><span> </span></li>
<li class="alt"><span>getId(</span><span class="string">"content"</span><span>).style.border = </span><span class="string">"1px solid #54ce43"</span><span> </span></li>
<li class=""><span>focs() </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> outInput(a){ </span></li>
<li class="alt"><span>getId(</span><span class="string">"btn"</span><span>).style.border = </span><span class="string">"1px solid #AAA"</span><span> </span></li>
<li class=""><span>getId(</span><span class="string">"content"</span><span>).style.border = </span><span class="string">"1px solid #AAA"</span><span> </span></li>
<li class="alt"><span>focs() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> overBtn(a){ </span></li>
<li class=""><span>a.src = </span><span class="string">"images/hover.gif"</span><span> </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> outBtn(a){ </span></li>
<li class="alt"><span>a.src = </span><span class="string">"images/rest.gif"</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> lrover(a){ </span></li>
<li class=""><span>a.style.backgroundColor = </span><span class="string">"#EEE"</span><span> </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> lrout(a){ </span></li>
<li class="alt"><span>a.style.backgroundColor = </span><span class="string">"#FFF"</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> focs(){ </span></li>
<li class=""><span>getName(</span><span class="string">"content"</span><span>).focus(); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> clean(){ </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).value = </span><span class="string">""</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> chats = </span><span class="keyword">new</span><span> Array() </span></li>
<li class=""><span></span><span class="keyword">var</span><span> chatStart </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> addChat(strChat){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(chats.length > 199){ </span></li>
<li class="alt"><span>chats.shift() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>chats.push(strChat) </span></li>
<li class=""><span>chatStart = chats.length </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> preChat(){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(chatStart && chatStart >= 1){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(chatStart == 1){ </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).value = chats[0] </span></li>
<li class=""><span>chatStart = 0.5 </span></li>
<li class="alt"><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class=""><span>chatStart -= 1 </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).value = chats[chatStart] </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>getId(</span><span class="string">"loadifo"</span><span>).innerHTML = chatStart+</span><span class="string">","</span><span>+chats.length </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> nextChat(){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(chatStart && chatStart < chats.length && chats.length > 1){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(chatStart == 0.5){ </span></li>
<li class="alt"><span>chatStart = 1 </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span> </span><span class="keyword">if</span><span>(chatStart == chats.length - 1){ </span></li>
<li class="alt"><span>chatStart = chats.length - 1 </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class="alt"><span>chatStart += 1 </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).value = chats[chatStart] </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getId(</span><span class="string">"loadifo"</span><span>).innerHTML = chatStart+</span><span class="string">","</span><span>+chats.length </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>window.onload = </span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>getId(</span><span class="string">"outs"</span><span>).onmousedown = </span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>overs = 1 </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getId(</span><span class="string">"outs"</span><span>).onmouseout = </span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>overs = 0 </span></li>
<li class="alt"><span>focs() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).onkeydown = </span><span class="keyword">function</span><span>(e){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(document.all){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> Keys = event.keyCode; </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> Keys = e.which; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="comment">//alert(Keys) </span><span> </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(Keys == </span><span class="string">"38"</span><span>){ </span></li>
<li class="alt"><span>preChat() </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span> </span><span class="keyword">if</span><span>(Keys == </span><span class="string">"40"</span><span>){ </span></li>
<li class="alt"><span>nextChat() </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span> </span><span class="keyword">if</span><span>(event.ctrlKey && Keys == </span><span class="string">"13"</span><span>){ </span></li>
<li class="alt"><span>doUsingPost() </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span> </span><span class="keyword">if</span><span>(event.ctrlKey && Keys == </span><span class="string">"46"</span><span>){ </span></li>
<li class="alt"><span>clean() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> getId(objId){ </span></li>
<li class="alt"><span></span><span class="keyword">return</span><span> document.getElementById(objId) </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> getName(objName){ </span></li>
<li class=""><span></span><span class="keyword">return</span><span> document.getElementsByName(objName)[0] </span></li>
<li class="alt"><span>} </span></li>
</ol>
</div>
<br />
<font color="#ff0000"><strong>chat.js</strong></font><br />
<div class="code_title">js 代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-c">
<li class="alt"><span><span class="keyword">var</span><span> overs; </span></span></li>
<li class=""><span></span><span class="keyword">var</span><span> clien = 0; </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> doUsingGet(){ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> ajax=</span><span class="keyword">new</span><span> sack(</span><span class="string">"chat.jsp"</span><span>); </span></li>
<li class="alt"><span>ajax.setVar(</span><span class="string">"clien"</span><span>,clien); </span></li>
<li class=""><span>ajax.setVar(</span><span class="string">"timeStamp"</span><span>,</span><span class="keyword">new</span><span> Date().getTime()); </span></li>
<li class="alt"><span>ajax.method='GET'; </span></li>
<li class=""><span>ajax.onLoading=</span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"读取中......"</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.onCompletion=</span><span class="keyword">function</span><span>(){</span><span class="comment">// 信息返回之后执行的方法 </span><span> </span></li>
<li class=""><span>CheckState(ajax.responseXML.documentElement); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.onLoaded=</span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"已经读取......"</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.onInteractive=</span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"交互中......"</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.complete = </span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"处理完毕......"</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.runAJAX(); </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> doUsingPost(){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(getName(</span><span class="string">"content"</span><span>).value!=</span><span class="string">""</span><span>){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> named = getName(</span><span class="string">"named"</span><span>).value; </span></li>
<li class=""><span></span><span class="keyword">var</span><span> content = getName(</span><span class="string">"content"</span><span>).value; </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> ajax=</span><span class="keyword">new</span><span> sack(</span><span class="string">"chat.jsp"</span><span>); </span></li>
<li class=""><span>ajax.setVar(</span><span class="string">"clien"</span><span>,clien); </span></li>
<li class="alt"><span>ajax.setVar(</span><span class="string">"content"</span><span>,content); </span></li>
<li class=""><span>ajax.setVar(</span><span class="string">"named"</span><span>,named); </span></li>
<li class="alt"><span>ajax.setVar(</span><span class="string">"timeStamp"</span><span>,</span><span class="keyword">new</span><span> Date().getTime()); </span></li>
<li class=""><span>ajax.method='POST'; </span></li>
<li class="alt"><span>ajax.onLoading=</span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"读取中......"</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.onCompletion=</span><span class="keyword">function</span><span>(){</span><span class="comment">// 信息返回之后执行的方法 </span><span> </span></li>
<li class="alt"><span>CheckState(ajax.responseXML.documentElement); </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.onLoaded=</span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"已经读取......"</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.onInteractive=</span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"交互中......"</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.complete = </span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"处理完毕......"</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.runAJAX(); </span></li>
<li class="alt"><span>focs(); </span></li>
<li class=""><span>clean(); </span></li>
<li class="alt"><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class=""><span>alert(</span><span class="string">"请输入对话内容!"</span><span>) </span></li>
<li class="alt"><span>focs() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">function</span><span> CheckState(res){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> resLen = res.getElementsByTagName(</span><span class="string">"items"</span><span>).length </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(getTag(res,0,</span><span class="string">"num"</span><span>) != clien){ </span></li>
<li class="alt"><span>clien = getTag(res,0,</span><span class="string">"num"</span><span>) </span></li>
<li class=""><span></span><span class="keyword">for</span><span>(</span><span class="keyword">var</span><span> i=0; i<resLen; i++){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> useName = getTag(res,i,</span><span class="string">"name"</span><span>) </span></li>
<li class=""><span></span><span class="keyword">var</span><span> useMag = getTag(res,i,</span><span class="string">"conts"</span><span>) </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> useIp = getTag(res,i,</span><span class="string">"ip"</span><span>) </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(clien != </span><span class="string">"0"</span><span> && useMag != </span><span class="string">""</span><span>){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(useName != </span><span class="string">""</span><span>){ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> lis = </span><span class="string">"用户"</span><span>+ useName + </span><span class="string">"说:"</span><span> + useMag </span><span class="comment">//+ " ["+ useIp + "]" </span><span> </span></li>
<li class="alt"><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> lis = </span><span class="string">"用户 ["</span><span>+ useIp + </span><span class="string">"] 说:"</span><span> + useMag </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> lis = </span><span class="string">""</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getId(</span><span class="string">"chatmain"</span><span>).innerHTML += lis + </span><span class="string">"<br />"</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>innerSize() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> innerSize(){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(overs != 1){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(getId(</span><span class="string">"chatmain"</span><span>).offsetHeight < getId(</span><span class="string">"outmain"</span><span>).offsetHeight){ </span></li>
<li class=""><span>getId(</span><span class="string">"chatmain"</span><span>).style.marginTop = getId(</span><span class="string">"outmain"</span><span>).offsetHeight - getId(</span><span class="string">"chatmain"</span><span>).offsetHeight +</span><span class="string">"px"</span><span>; </span></li>
<li class="alt"><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class=""><span>getId(</span><span class="string">"chatmain"</span><span>).scrollIntoView(</span><span class="keyword">false</span><span>) </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> getTag(response,i,objTagName){ </span></li>
<li class="alt"><span></span><span class="keyword">try</span><span>{ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> nodeV = response.getElementsByTagName(objTagName)[i].firstChild.nodeValue; </span></li>
<li class="alt"><span>}</span><span class="keyword">catch</span><span>(e){ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> nodeV = </span><span class="string">""</span><span> </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">return</span><span> nodeV; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>setInterval(</span><span class="string">"doUsingGet()"</span><span>,1000) </span></li>
</ol>
</div>
<br />
<br />
<strong><span style="COLOR: #ff0000">chat.jsp</span></strong><br />
<div class="code_title">jsp代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span>%@ page </span><span class="attribute">contentType</span><span>=</span><span class="attribute-value">"text/xml; charset=gb2312"</span><span> %</span><span class="tag">></span><span> </span></span></li>
<li class=""><span></span><span class="tag"><</span><span>%! </span></li>
<li class="alt"><span>String func(String content){ </span></li>
<li class=""><span>return content.replaceAll("</span><span class="tag"><</span><span>","<").replaceAll("</span><span class="tag">></span><span>",">"); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>%</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span>% </span></li>
<li class=""><span>String </span><span class="attribute">ip</span><span>=</span><span class="attribute-value">request</span><span>.getRemoteAddr(); //客户端IP </span></li>
<li class="alt"><span>int </span><span class="attribute">clien</span><span> = </span><span class="attribute-value">new</span><span> Integer(request.getParameter("clien")).intValue(); //当前是第几个用户 如果为0就是新来的用户 </span></li>
<li class=""><span>if(application.getAttribute("counts")==null){ </span></li>
<li class="alt"><span>application.setAttribute("counts",new Integer(0)); </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>int </span><span class="attribute">counts</span><span> = </span><span class="attribute-value">new</span><span> Integer(application.getAttribute("counts").toString()).intValue(); //当前用户的ID </span></li>
<li class=""><span>if(request.getParameter("content")!=null){ </span></li>
<li class="alt"><span>synchronized(this){ </span></li>
<li class=""><span>if(counts </span><span class="tag"><</span><span> </span><span class="tag-name">21</span><span>){ </span></li>
<li class="alt"><span>int </span><span class="attribute">i</span><span> = </span><span class="attribute-value">counts</span><span> + 1; </span></li>
<li class=""><span>application.setAttribute("counts",new Integer(i)); </span></li>
<li class="alt"><span>}else if(counts </span><span class="tag">></span><span>= 21){ </span></li>
<li class=""><span>application.setAttribute("counts","1"); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="attribute">counts</span><span> = </span><span class="attribute-value">new</span><span> Integer(application.getAttribute("counts").toString()).intValue(); //当前用户的ID </span></li>
<li class="alt"><span>int </span><span class="attribute">Cnum</span><span> = </span><span class="attribute-value">counts</span><span>; </span></li>
<li class=""><span>String names; </span></li>
<li class="alt"><span>String </span><span class="attribute">Msgs</span><span> = </span><span class="attribute-value">request</span><span>.getParameter("content"); </span></li>
<li class=""><span>// </span><span class="attribute">Msgs</span><span>=</span><span class="attribute-value">new</span><span> String(Msgs.getBytes("iso8859-1"),"gb2312"); </span></li>
<li class="alt"><span>application.setAttribute("ips" + Cnum,ip) ; </span></li>
<li class=""><span>application.setAttribute("msgs" + Cnum,func(Msgs)) ; </span></li>
<li class="alt"><span>if(request.getParameterValues("content") != null){ </span></li>
<li class=""><span></span><span class="attribute">names</span><span> = </span><span class="attribute-value">request</span><span>.getParameter("named"); </span></li>
<li class="alt"><span>}else{ </span></li>
<li class=""><span></span><span class="attribute">names</span><span> = </span><span class="attribute-value">""</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>application.setAttribute("names" + Cnum,names +"") ; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>%</span><span class="tag">></span><span class="tag"><?</span><span class="tag-name">xml</span><span> </span><span class="attribute">version</span><span>=</span><span class="attribute-value">"1.0"</span><span> </span><span class="attribute">encoding</span><span>=</span><span class="attribute-value">"gb2312"</span><span> </span><span class="tag">?></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">ppl</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">num</span><span class="tag">></span><span class="tag"><</span><span>%=application.getAttribute("counts")%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">num</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span>% </span></li>
<li class="alt"><span>if(</span><span class="attribute">clien</span><span> == 0){ </span></li>
<li class=""><span>%</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">ip</span><span class="tag">></span><span class="tag"><</span><span>%=ip%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ip</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"></</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span>% </span></li>
<li class="alt"><span>}else if(clien </span><span class="tag"><</span><span> </span><span class="tag-name">counts</span><span>){ </span></li>
<li class=""><span>for(int </span><span class="attribute">i</span><span>=</span><span class="attribute-value">clien</span><span>; i</span><span class="tag"><</span><span class="tag-name">counts</span><span>; i++){ </span></li>
<li class="alt"><span>int </span><span class="attribute">s</span><span> = </span><span class="attribute-value">i</span><span>+1; </span></li>
<li class=""><span>String </span><span class="attribute">useName</span><span> = (String)application.getAttribute("names" + s); </span></li>
<li class="alt"><span>String </span><span class="attribute">useMsg</span><span> = (String)application.getAttribute("msgs" + s); </span></li>
<li class=""><span>String </span><span class="attribute">useIp</span><span> = (String)application.getAttribute("ips" + s); </span></li>
<li class="alt"><span>%</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">aaa</span><span class="tag">></span><span class="tag"><</span><span>%=clien%</span><span class="tag">></span><span> </span><span class="tag"><</span><span>%=s%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">aaa</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">bbb</span><span class="tag">></span><span class="tag"><</span><span>%=counts%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">bbb</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span><span class="tag"><</span><span>%=useName%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">conts</span><span class="tag">></span><span class="tag"><</span><span>%=useMsg%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">conts</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">ip</span><span class="tag">></span><span class="tag"><</span><span>%=useIp%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ip</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"></</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span>% </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>}else if(clien </span><span class="tag">></span><span> counts){ </span></li>
<li class=""><span>for(int </span><span class="attribute">i</span><span>=</span><span class="attribute-value">clien</span><span>; i</span><span class="tag"><</span><span class="tag-name">21</span><span>; i++){ </span></li>
<li class="alt"><span>String </span><span class="attribute">useName</span><span> = (String)application.getAttribute("names" + i); </span></li>
<li class=""><span>String </span><span class="attribute">useMsg</span><span> = (String)application.getAttribute("msgs" + i); </span></li>
<li class="alt"><span>String </span><span class="attribute">useIp</span><span> = (String)application.getAttribute("ips" + i); </span></li>
<li class=""><span>%</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span><span class="tag"><</span><span>%=useName%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">conts</span><span class="tag">></span><span class="tag"><</span><span>%=useMsg%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">conts</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">ip</span><span class="tag">></span><span class="tag"><</span><span>%=useIp%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ip</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"></</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span>% </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>for(int </span><span class="attribute">m</span><span>=</span><span class="attribute-value">1</span><span>; m</span><span class="tag"><</span><span>=counts; m++){ </span></li>
<li class="alt"><span>String </span><span class="attribute">useNameM</span><span> = (String)application.getAttribute("names" + m); </span></li>
<li class=""><span>String </span><span class="attribute">useMsgM</span><span> = (String)application.getAttribute("msgs" + m); </span></li>
<li class="alt"><span>String </span><span class="attribute">useIpM</span><span> = (String)application.getAttribute("ips" + m); </span></li>
<li class=""><span>%</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span><span class="tag"><</span><span>%=useNameM%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">conts</span><span class="tag">></span><span class="tag"><</span><span>%=useMsgM%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">conts</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">ip</span><span class="tag">></span><span class="tag"><</span><span>%=useIpM%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ip</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"></</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span>% </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>}else if(</span><span class="attribute">clien</span><span> == counts){ </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>%</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"></</span><span class="tag-name">ppl</span><span class="tag">></span><span> </span></li>
</ol>
</div>
<br />
<strong><span style="COLOR: #ff0000">index.html</span></strong><br />
<div class="code_title">html 代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-xml">
<li class="alt"><span><span><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span class="tag">></span><span> </span></span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">html</span><span> </span><span class="attribute">xmlns</span><span>=</span><span class="attribute-value">"http://www.w3.org/1999/xhtml"</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">head</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"Content-Type"</span><span> </span><span class="attribute">content</span><span>=</span><span class="attribute-value">"text/html; charset=gb2312"</span><span> </span><span class="tag">/></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">title</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">title</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">link</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">"images/chatstyle.css"</span><span> </span><span class="attribute">rel</span><span>=</span><span class="attribute-value">"stylesheet"</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/css"</span><span> </span><span class="tag">/></span><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">script</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"js/display.js"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">script</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">script</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"js/chat.js"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">script</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">script</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"js/tw-sack.js"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">script</span><span class="tag">></span><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="tag"></</span><span class="tag-name">head</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">body</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"zt"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"loadifo"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"outs"</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"outmain"</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"chatmain"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"in"</span><span class="tag">></span><span>昵称: </span></li>
<li class=""
<div class="code_title">js 代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-c">
<li class="alt"><span><span class="comment">/* Simple AJAX Code-Kit (SACK) */</span><span> </span></span></li>
<li class=""><span></span><span class="comment">/* 2005 Gregory Wild-Smith */</span><span> </span></li>
<li class="alt"><span></span><span class="comment">/* www.twilightuniverse.com */</span><span> </span></li>
<li class=""><span></span><span class="comment">/* Software licenced under a modified X11 licence, see documentation or authors website for more details */</span><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">function</span><span> sack(file){ </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.AjaxFailedAlert = </span><span class="string">"Your browser does not support the enhanced functionality of this website, and therefore you will have an experience that differs from the intended one.\n"</span><span>; </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.requestFile = file; </span><span class="comment">// 提交的页面 </span><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.method = </span><span class="string">"POST"</span><span>; </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString = </span><span class="string">""</span><span>; </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.encodeURIString = </span><span class="keyword">true</span><span>; </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.execute = </span><span class="keyword">false</span><span>; </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.onLoading = </span><span class="keyword">function</span><span>() { };</span><span class="comment">//读取中 </span><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.onLoaded = </span><span class="keyword">function</span><span>() { };</span><span class="comment">//已经读取 </span><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.onInteractive = </span><span class="keyword">function</span><span>() { };</span><span class="comment">//交互中 </span><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.onCompletion = </span><span class="keyword">function</span><span>() { }; </span><span class="comment">// 信息返回之后执行的方法 </span><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.complete = </span><span class="keyword">function</span><span>(){};</span><span class="comment">//处理完毕 </span><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.createAJAX = </span><span class="keyword">function</span><span>() { </span></li>
<li class=""><span></span><span class="keyword">try</span><span> { </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp = </span><span class="keyword">new</span><span> ActiveXObject(</span><span class="string">"Microsoft.XMLHTTP"</span><span>); </span></li>
<li class=""><span>} </span><span class="keyword">catch</span><span> (e) { </span></li>
<li class="alt"><span></span><span class="keyword">try</span><span> { </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.xmlhttp = </span><span class="keyword">new</span><span> ActiveXObject(</span><span class="string">"Msxml2.XMLHTTP"</span><span>); </span></li>
<li class="alt"><span>} </span><span class="keyword">catch</span><span> (err) { </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.xmlhttp = </span><span class="keyword">null</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(!</span><span class="keyword">this</span><span>.xmlhttp && </span><span class="keyword">typeof</span><span> XMLHttpRequest != </span><span class="string">"undefined"</span><span>) </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.xmlhttp = </span><span class="keyword">new</span><span> XMLHttpRequest(); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (!</span><span class="keyword">this</span><span>.xmlhttp){ </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.failed = </span><span class="keyword">true</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>}; </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.setVar = </span><span class="keyword">function</span><span>(name, value){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.URLString.length < 3){ </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString = name + </span><span class="string">"="</span><span> + value; </span></li>
<li class="alt"><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString += </span><span class="string">"&"</span><span> + name + </span><span class="string">"="</span><span> + value; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.encVar = </span><span class="keyword">function</span><span>(name, value){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> varString = encodeURIComponent(name) + </span><span class="string">"="</span><span> + encodeURIComponent(value); </span></li>
<li class=""><span></span><span class="keyword">return</span><span> varString; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.encodeURLString = </span><span class="keyword">function</span><span>(string){ </span></li>
<li class=""><span>varArray = string.split('&'); </span></li>
<li class="alt"><span></span><span class="keyword">for</span><span> (i = 0; i < varArray.length; i++){ </span></li>
<li class=""><span>urlVars = varArray[i].split('='); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (urlVars[0].indexOf('amp;') != -1){ </span></li>
<li class=""><span>urlVars[0] = urlVars[0].substring(4); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>varArray[i] = </span><span class="keyword">this</span><span>.encVar(urlVars[0],urlVars[1]); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">return</span><span> varArray.join('&'); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.runResponse = </span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>eval(</span><span class="keyword">this</span><span>.response); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.runAJAX = </span><span class="keyword">function</span><span>(urlstring){ </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.responseStatus = </span><span class="keyword">new</span><span> Array(2); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(</span><span class="keyword">this</span><span>.failed && </span><span class="keyword">this</span><span>.AjaxFailedAlert){ </span></li>
<li class=""><span>alert(</span><span class="keyword">this</span><span>.AjaxFailedAlert); </span></li>
<li class="alt"><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class=""><span></span><span class="keyword">if</span><span> (urlstring){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.URLString.length){ </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString = </span><span class="keyword">this</span><span>.URLString + </span><span class="string">"&"</span><span> + urlstring; </span></li>
<li class="alt"><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.URLString = urlstring; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.encodeURIString){ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> timeval = </span><span class="keyword">new</span><span> Date().getTime(); </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.URLString = </span><span class="keyword">this</span><span>.encodeURLString(</span><span class="keyword">this</span><span>.URLString); </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.setVar(</span><span class="string">"rndval"</span><span>, timeval); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.element) { </span><span class="keyword">this</span><span>.elementObj = document.getElementById(</span><span class="keyword">this</span><span>.element); } </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.xmlhttp) { </span></li>
<li class=""><span></span><span class="keyword">var</span><span> self = </span><span class="keyword">this</span><span>; </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.method == </span><span class="string">"GET"</span><span>) { </span></li>
<li class=""><span></span><span class="keyword">var</span><span> totalurlstring = </span><span class="keyword">this</span><span>.requestFile + </span><span class="string">"?"</span><span> + </span><span class="keyword">this</span><span>.URLString; </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp.open(</span><span class="keyword">this</span><span>.method, totalurlstring, </span><span class="keyword">true</span><span>); </span></li>
<li class=""><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp.open(</span><span class="keyword">this</span><span>.method, </span><span class="keyword">this</span><span>.requestFile, </span><span class="keyword">true</span><span>); </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (</span><span class="keyword">this</span><span>.method == </span><span class="string">"POST"</span><span>){ </span></li>
<li class=""><span></span><span class="keyword">try</span><span> { </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8') </span></li>
<li class=""><span>} </span><span class="keyword">catch</span><span> (e) {} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.xmlhttp.send(</span><span class="keyword">this</span><span>.URLString); </span></li>
<li class=""><span></span><span class="keyword">this</span><span>.xmlhttp.onreadystatechange = </span><span class="keyword">function</span><span>() { </span></li>
<li class="alt"><span></span><span class="keyword">switch</span><span> (self.xmlhttp.readyState){ </span></li>
<li class=""><span></span><span class="keyword">case</span><span> 1: </span><span class="comment">//读取中 </span><span> </span></li>
<li class="alt"><span>self.onLoading(); </span></li>
<li class=""><span></span><span class="keyword">break</span><span>; </span></li>
<li class="alt"><span></span><span class="keyword">case</span><span> 2: </span><span class="comment">//已经读取 </span><span> </span></li>
<li class=""><span>self.onLoaded(); </span></li>
<li class="alt"><span></span><span class="keyword">break</span><span>; </span></li>
<li class=""><span></span><span class="keyword">case</span><span> 3: </span><span class="comment">//交互中 </span><span> </span></li>
<li class="alt"><span>self.onInteractive(); </span></li>
<li class=""><span></span><span class="keyword">break</span><span>; </span></li>
<li class="alt"><span></span><span class="keyword">case</span><span> 4: </span><span class="comment">//处理完毕 </span><span> </span></li>
<li class=""><span>self.response = self.xmlhttp.responseText; </span></li>
<li class="alt"><span>self.responseXML = self.xmlhttp.responseXML; </span></li>
<li class=""><span>self.responseStatus[0] = self.xmlhttp.status; </span></li>
<li class="alt"><span>self.responseStatus[1] = self.xmlhttp.statusText; </span></li>
<li class=""><span>self.onCompletion(); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(self.execute){ self.runResponse(); } </span></li>
<li class=""><span></span><span class="keyword">if</span><span> (self.elementObj) { </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> elemNodeName = self.elementObj.nodeName; </span></li>
<li class=""><span>elemNodeName.toLowerCase(); </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span> (elemNodeName == </span><span class="string">"input"</span><span> || elemNodeName == </span><span class="string">"select"</span><span> || elemNodeName == </span><span class="string">"option"</span><span> || elemNodeName == </span><span class="string">"textarea"</span><span>){ </span></li>
<li class=""><span>self.elementObj.value = self.response; </span></li>
<li class="alt"><span>} </span><span class="keyword">else</span><span> { </span></li>
<li class=""><span>self.elementObj.innerHTML = self.response; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>self.URLString = </span><span class="string">""</span><span>; </span></li>
<li class=""><span>self.complete(); </span></li>
<li class="alt"><span></span><span class="keyword">break</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>}; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>}; </span></li>
<li class="alt"><span></span><span class="keyword">this</span><span>.createAJAX(); </span></li>
<li class=""><span>} </span></li>
</ol>
</div>
<br />
<strong><span style="COLOR: #ff0000">display.js</span></strong><br />
<div class="code_title">js 代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-c">
<li class="alt"><span><span class="keyword">function</span><span> overInput(a){ </span></span></li>
<li class=""><span>getId(</span><span class="string">"btn"</span><span>).style.border = </span><span class="string">"1px solid #54ce43"</span><span> </span></li>
<li class="alt"><span>getId(</span><span class="string">"content"</span><span>).style.border = </span><span class="string">"1px solid #54ce43"</span><span> </span></li>
<li class=""><span>focs() </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> outInput(a){ </span></li>
<li class="alt"><span>getId(</span><span class="string">"btn"</span><span>).style.border = </span><span class="string">"1px solid #AAA"</span><span> </span></li>
<li class=""><span>getId(</span><span class="string">"content"</span><span>).style.border = </span><span class="string">"1px solid #AAA"</span><span> </span></li>
<li class="alt"><span>focs() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> overBtn(a){ </span></li>
<li class=""><span>a.src = </span><span class="string">"images/hover.gif"</span><span> </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> outBtn(a){ </span></li>
<li class="alt"><span>a.src = </span><span class="string">"images/rest.gif"</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> lrover(a){ </span></li>
<li class=""><span>a.style.backgroundColor = </span><span class="string">"#EEE"</span><span> </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> lrout(a){ </span></li>
<li class="alt"><span>a.style.backgroundColor = </span><span class="string">"#FFF"</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> focs(){ </span></li>
<li class=""><span>getName(</span><span class="string">"content"</span><span>).focus(); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> clean(){ </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).value = </span><span class="string">""</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> chats = </span><span class="keyword">new</span><span> Array() </span></li>
<li class=""><span></span><span class="keyword">var</span><span> chatStart </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> addChat(strChat){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(chats.length > 199){ </span></li>
<li class="alt"><span>chats.shift() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>chats.push(strChat) </span></li>
<li class=""><span>chatStart = chats.length </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> preChat(){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(chatStart && chatStart >= 1){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(chatStart == 1){ </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).value = chats[0] </span></li>
<li class=""><span>chatStart = 0.5 </span></li>
<li class="alt"><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class=""><span>chatStart -= 1 </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).value = chats[chatStart] </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>getId(</span><span class="string">"loadifo"</span><span>).innerHTML = chatStart+</span><span class="string">","</span><span>+chats.length </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> nextChat(){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(chatStart && chatStart < chats.length && chats.length > 1){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(chatStart == 0.5){ </span></li>
<li class="alt"><span>chatStart = 1 </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span> </span><span class="keyword">if</span><span>(chatStart == chats.length - 1){ </span></li>
<li class="alt"><span>chatStart = chats.length - 1 </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class="alt"><span>chatStart += 1 </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).value = chats[chatStart] </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getId(</span><span class="string">"loadifo"</span><span>).innerHTML = chatStart+</span><span class="string">","</span><span>+chats.length </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>window.onload = </span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>getId(</span><span class="string">"outs"</span><span>).onmousedown = </span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>overs = 1 </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getId(</span><span class="string">"outs"</span><span>).onmouseout = </span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>overs = 0 </span></li>
<li class="alt"><span>focs() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getName(</span><span class="string">"content"</span><span>).onkeydown = </span><span class="keyword">function</span><span>(e){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(document.all){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> Keys = event.keyCode; </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> Keys = e.which; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="comment">//alert(Keys) </span><span> </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(Keys == </span><span class="string">"38"</span><span>){ </span></li>
<li class="alt"><span>preChat() </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span> </span><span class="keyword">if</span><span>(Keys == </span><span class="string">"40"</span><span>){ </span></li>
<li class="alt"><span>nextChat() </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span> </span><span class="keyword">if</span><span>(event.ctrlKey && Keys == </span><span class="string">"13"</span><span>){ </span></li>
<li class="alt"><span>doUsingPost() </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span> </span><span class="keyword">if</span><span>(event.ctrlKey && Keys == </span><span class="string">"46"</span><span>){ </span></li>
<li class="alt"><span>clean() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> getId(objId){ </span></li>
<li class="alt"><span></span><span class="keyword">return</span><span> document.getElementById(objId) </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> getName(objName){ </span></li>
<li class=""><span></span><span class="keyword">return</span><span> document.getElementsByName(objName)[0] </span></li>
<li class="alt"><span>} </span></li>
</ol>
</div>
<br />
<font color="#ff0000"><strong>chat.js</strong></font><br />
<div class="code_title">js 代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-c">
<li class="alt"><span><span class="keyword">var</span><span> overs; </span></span></li>
<li class=""><span></span><span class="keyword">var</span><span> clien = 0; </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> doUsingGet(){ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> ajax=</span><span class="keyword">new</span><span> sack(</span><span class="string">"chat.jsp"</span><span>); </span></li>
<li class="alt"><span>ajax.setVar(</span><span class="string">"clien"</span><span>,clien); </span></li>
<li class=""><span>ajax.setVar(</span><span class="string">"timeStamp"</span><span>,</span><span class="keyword">new</span><span> Date().getTime()); </span></li>
<li class="alt"><span>ajax.method='GET'; </span></li>
<li class=""><span>ajax.onLoading=</span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"读取中......"</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.onCompletion=</span><span class="keyword">function</span><span>(){</span><span class="comment">// 信息返回之后执行的方法 </span><span> </span></li>
<li class=""><span>CheckState(ajax.responseXML.documentElement); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.onLoaded=</span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"已经读取......"</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.onInteractive=</span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"交互中......"</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.complete = </span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"处理完毕......"</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.runAJAX(); </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> doUsingPost(){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(getName(</span><span class="string">"content"</span><span>).value!=</span><span class="string">""</span><span>){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> named = getName(</span><span class="string">"named"</span><span>).value; </span></li>
<li class=""><span></span><span class="keyword">var</span><span> content = getName(</span><span class="string">"content"</span><span>).value; </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> ajax=</span><span class="keyword">new</span><span> sack(</span><span class="string">"chat.jsp"</span><span>); </span></li>
<li class=""><span>ajax.setVar(</span><span class="string">"clien"</span><span>,clien); </span></li>
<li class="alt"><span>ajax.setVar(</span><span class="string">"content"</span><span>,content); </span></li>
<li class=""><span>ajax.setVar(</span><span class="string">"named"</span><span>,named); </span></li>
<li class="alt"><span>ajax.setVar(</span><span class="string">"timeStamp"</span><span>,</span><span class="keyword">new</span><span> Date().getTime()); </span></li>
<li class=""><span>ajax.method='POST'; </span></li>
<li class="alt"><span>ajax.onLoading=</span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"读取中......"</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.onCompletion=</span><span class="keyword">function</span><span>(){</span><span class="comment">// 信息返回之后执行的方法 </span><span> </span></li>
<li class="alt"><span>CheckState(ajax.responseXML.documentElement); </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.onLoaded=</span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"已经读取......"</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.onInteractive=</span><span class="keyword">function</span><span>(){ </span></li>
<li class="alt"><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"交互中......"</span><span>; </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>ajax.complete = </span><span class="keyword">function</span><span>(){ </span></li>
<li class=""><span>document.getElementById(</span><span class="string">"zt"</span><span>).innerHTML=</span><span class="string">"处理完毕......"</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>ajax.runAJAX(); </span></li>
<li class="alt"><span>focs(); </span></li>
<li class=""><span>clean(); </span></li>
<li class="alt"><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class=""><span>alert(</span><span class="string">"请输入对话内容!"</span><span>) </span></li>
<li class="alt"><span>focs() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="keyword">function</span><span> CheckState(res){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> resLen = res.getElementsByTagName(</span><span class="string">"items"</span><span>).length </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(getTag(res,0,</span><span class="string">"num"</span><span>) != clien){ </span></li>
<li class="alt"><span>clien = getTag(res,0,</span><span class="string">"num"</span><span>) </span></li>
<li class=""><span></span><span class="keyword">for</span><span>(</span><span class="keyword">var</span><span> i=0; i<resLen; i++){ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> useName = getTag(res,i,</span><span class="string">"name"</span><span>) </span></li>
<li class=""><span></span><span class="keyword">var</span><span> useMag = getTag(res,i,</span><span class="string">"conts"</span><span>) </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> useIp = getTag(res,i,</span><span class="string">"ip"</span><span>) </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(clien != </span><span class="string">"0"</span><span> && useMag != </span><span class="string">""</span><span>){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(useName != </span><span class="string">""</span><span>){ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> lis = </span><span class="string">"用户"</span><span>+ useName + </span><span class="string">"说:"</span><span> + useMag </span><span class="comment">//+ " ["+ useIp + "]" </span><span> </span></li>
<li class="alt"><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> lis = </span><span class="string">"用户 ["</span><span>+ useIp + </span><span class="string">"] 说:"</span><span> + useMag </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class="alt"><span></span><span class="keyword">var</span><span> lis = </span><span class="string">""</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>getId(</span><span class="string">"chatmain"</span><span>).innerHTML += lis + </span><span class="string">"<br />"</span><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>innerSize() </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span> </span></li>
<li class="alt"><span></span><span class="keyword">function</span><span> innerSize(){ </span></li>
<li class=""><span></span><span class="keyword">if</span><span>(overs != 1){ </span></li>
<li class="alt"><span></span><span class="keyword">if</span><span>(getId(</span><span class="string">"chatmain"</span><span>).offsetHeight < getId(</span><span class="string">"outmain"</span><span>).offsetHeight){ </span></li>
<li class=""><span>getId(</span><span class="string">"chatmain"</span><span>).style.marginTop = getId(</span><span class="string">"outmain"</span><span>).offsetHeight - getId(</span><span class="string">"chatmain"</span><span>).offsetHeight +</span><span class="string">"px"</span><span>; </span></li>
<li class="alt"><span>}</span><span class="keyword">else</span><span>{ </span></li>
<li class=""><span>getId(</span><span class="string">"chatmain"</span><span>).scrollIntoView(</span><span class="keyword">false</span><span>) </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">function</span><span> getTag(response,i,objTagName){ </span></li>
<li class="alt"><span></span><span class="keyword">try</span><span>{ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> nodeV = response.getElementsByTagName(objTagName)[i].firstChild.nodeValue; </span></li>
<li class="alt"><span>}</span><span class="keyword">catch</span><span>(e){ </span></li>
<li class=""><span></span><span class="keyword">var</span><span> nodeV = </span><span class="string">""</span><span> </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="keyword">return</span><span> nodeV; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>setInterval(</span><span class="string">"doUsingGet()"</span><span>,1000) </span></li>
</ol>
</div>
<br />
<br />
<strong><span style="COLOR: #ff0000">chat.jsp</span></strong><br />
<div class="code_title">jsp代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span>%@ page </span><span class="attribute">contentType</span><span>=</span><span class="attribute-value">"text/xml; charset=gb2312"</span><span> %</span><span class="tag">></span><span> </span></span></li>
<li class=""><span></span><span class="tag"><</span><span>%! </span></li>
<li class="alt"><span>String func(String content){ </span></li>
<li class=""><span>return content.replaceAll("</span><span class="tag"><</span><span>","<").replaceAll("</span><span class="tag">></span><span>",">"); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>%</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span>% </span></li>
<li class=""><span>String </span><span class="attribute">ip</span><span>=</span><span class="attribute-value">request</span><span>.getRemoteAddr(); //客户端IP </span></li>
<li class="alt"><span>int </span><span class="attribute">clien</span><span> = </span><span class="attribute-value">new</span><span> Integer(request.getParameter("clien")).intValue(); //当前是第几个用户 如果为0就是新来的用户 </span></li>
<li class=""><span>if(application.getAttribute("counts")==null){ </span></li>
<li class="alt"><span>application.setAttribute("counts",new Integer(0)); </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>int </span><span class="attribute">counts</span><span> = </span><span class="attribute-value">new</span><span> Integer(application.getAttribute("counts").toString()).intValue(); //当前用户的ID </span></li>
<li class=""><span>if(request.getParameter("content")!=null){ </span></li>
<li class="alt"><span>synchronized(this){ </span></li>
<li class=""><span>if(counts </span><span class="tag"><</span><span> </span><span class="tag-name">21</span><span>){ </span></li>
<li class="alt"><span>int </span><span class="attribute">i</span><span> = </span><span class="attribute-value">counts</span><span> + 1; </span></li>
<li class=""><span>application.setAttribute("counts",new Integer(i)); </span></li>
<li class="alt"><span>}else if(counts </span><span class="tag">></span><span>= 21){ </span></li>
<li class=""><span>application.setAttribute("counts","1"); </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span></span><span class="attribute">counts</span><span> = </span><span class="attribute-value">new</span><span> Integer(application.getAttribute("counts").toString()).intValue(); //当前用户的ID </span></li>
<li class="alt"><span>int </span><span class="attribute">Cnum</span><span> = </span><span class="attribute-value">counts</span><span>; </span></li>
<li class=""><span>String names; </span></li>
<li class="alt"><span>String </span><span class="attribute">Msgs</span><span> = </span><span class="attribute-value">request</span><span>.getParameter("content"); </span></li>
<li class=""><span>// </span><span class="attribute">Msgs</span><span>=</span><span class="attribute-value">new</span><span> String(Msgs.getBytes("iso8859-1"),"gb2312"); </span></li>
<li class="alt"><span>application.setAttribute("ips" + Cnum,ip) ; </span></li>
<li class=""><span>application.setAttribute("msgs" + Cnum,func(Msgs)) ; </span></li>
<li class="alt"><span>if(request.getParameterValues("content") != null){ </span></li>
<li class=""><span></span><span class="attribute">names</span><span> = </span><span class="attribute-value">request</span><span>.getParameter("named"); </span></li>
<li class="alt"><span>}else{ </span></li>
<li class=""><span></span><span class="attribute">names</span><span> = </span><span class="attribute-value">""</span><span>; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>application.setAttribute("names" + Cnum,names +"") ; </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>%</span><span class="tag">></span><span class="tag"><?</span><span class="tag-name">xml</span><span> </span><span class="attribute">version</span><span>=</span><span class="attribute-value">"1.0"</span><span> </span><span class="attribute">encoding</span><span>=</span><span class="attribute-value">"gb2312"</span><span> </span><span class="tag">?></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">ppl</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">num</span><span class="tag">></span><span class="tag"><</span><span>%=application.getAttribute("counts")%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">num</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span>% </span></li>
<li class="alt"><span>if(</span><span class="attribute">clien</span><span> == 0){ </span></li>
<li class=""><span>%</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">ip</span><span class="tag">></span><span class="tag"><</span><span>%=ip%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ip</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"></</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span>% </span></li>
<li class="alt"><span>}else if(clien </span><span class="tag"><</span><span> </span><span class="tag-name">counts</span><span>){ </span></li>
<li class=""><span>for(int </span><span class="attribute">i</span><span>=</span><span class="attribute-value">clien</span><span>; i</span><span class="tag"><</span><span class="tag-name">counts</span><span>; i++){ </span></li>
<li class="alt"><span>int </span><span class="attribute">s</span><span> = </span><span class="attribute-value">i</span><span>+1; </span></li>
<li class=""><span>String </span><span class="attribute">useName</span><span> = (String)application.getAttribute("names" + s); </span></li>
<li class="alt"><span>String </span><span class="attribute">useMsg</span><span> = (String)application.getAttribute("msgs" + s); </span></li>
<li class=""><span>String </span><span class="attribute">useIp</span><span> = (String)application.getAttribute("ips" + s); </span></li>
<li class="alt"><span>%</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">aaa</span><span class="tag">></span><span class="tag"><</span><span>%=clien%</span><span class="tag">></span><span> </span><span class="tag"><</span><span>%=s%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">aaa</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">bbb</span><span class="tag">></span><span class="tag"><</span><span>%=counts%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">bbb</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span><span class="tag"><</span><span>%=useName%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">conts</span><span class="tag">></span><span class="tag"><</span><span>%=useMsg%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">conts</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">ip</span><span class="tag">></span><span class="tag"><</span><span>%=useIp%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ip</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"></</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span>% </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>}else if(clien </span><span class="tag">></span><span> counts){ </span></li>
<li class=""><span>for(int </span><span class="attribute">i</span><span>=</span><span class="attribute-value">clien</span><span>; i</span><span class="tag"><</span><span class="tag-name">21</span><span>; i++){ </span></li>
<li class="alt"><span>String </span><span class="attribute">useName</span><span> = (String)application.getAttribute("names" + i); </span></li>
<li class=""><span>String </span><span class="attribute">useMsg</span><span> = (String)application.getAttribute("msgs" + i); </span></li>
<li class="alt"><span>String </span><span class="attribute">useIp</span><span> = (String)application.getAttribute("ips" + i); </span></li>
<li class=""><span>%</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span><span class="tag"><</span><span>%=useName%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">conts</span><span class="tag">></span><span class="tag"><</span><span>%=useMsg%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">conts</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">ip</span><span class="tag">></span><span class="tag"><</span><span>%=useIp%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ip</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"></</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span>% </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>for(int </span><span class="attribute">m</span><span>=</span><span class="attribute-value">1</span><span>; m</span><span class="tag"><</span><span>=counts; m++){ </span></li>
<li class="alt"><span>String </span><span class="attribute">useNameM</span><span> = (String)application.getAttribute("names" + m); </span></li>
<li class=""><span>String </span><span class="attribute">useMsgM</span><span> = (String)application.getAttribute("msgs" + m); </span></li>
<li class="alt"><span>String </span><span class="attribute">useIpM</span><span> = (String)application.getAttribute("ips" + m); </span></li>
<li class=""><span>%</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">name</span><span class="tag">></span><span class="tag"><</span><span>%=useNameM%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">name</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">conts</span><span class="tag">></span><span class="tag"><</span><span>%=useMsgM%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">conts</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">ip</span><span class="tag">></span><span class="tag"><</span><span>%=useIpM%</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">ip</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"></</span><span class="tag-name">items</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span>% </span></li>
<li class="alt"><span>} </span></li>
<li class=""><span>}else if(</span><span class="attribute">clien</span><span> == counts){ </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>} </span></li>
<li class="alt"><span>%</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"></</span><span class="tag-name">ppl</span><span class="tag">></span><span> </span></li>
</ol>
</div>
<br />
<strong><span style="COLOR: #ff0000">index.html</span></strong><br />
<div class="code_title">html 代码</div>
<div class="dp-highlighter">
<div class="bar"></div>
<ol class="dp-xml">
<li class="alt"><span><span><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span class="tag">></span><span> </span></span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">html</span><span> </span><span class="attribute">xmlns</span><span>=</span><span class="attribute-value">"http://www.w3.org/1999/xhtml"</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">head</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">meta</span><span> </span><span class="attribute">http-equiv</span><span>=</span><span class="attribute-value">"Content-Type"</span><span> </span><span class="attribute">content</span><span>=</span><span class="attribute-value">"text/html; charset=gb2312"</span><span> </span><span class="tag">/></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">title</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">title</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">link</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">"images/chatstyle.css"</span><span> </span><span class="attribute">rel</span><span>=</span><span class="attribute-value">"stylesheet"</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/css"</span><span> </span><span class="tag">/></span><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">script</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"js/display.js"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">script</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">script</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"js/chat.js"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">script</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">script</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text/javascript"</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">"js/tw-sack.js"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">script</span><span class="tag">></span><span> </span></li>
<li class="alt"><span> </span></li>
<li class=""><span></span><span class="tag"></</span><span class="tag-name">head</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">body</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"zt"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"loadifo"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></li>
<li class=""><span></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"outs"</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"outmain"</span><span class="tag">></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">"chatmain"</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span class="tag"></</span><span class="tag-name">div</span><span class="tag">></span><span> </span></li>
<li class="alt"><span></span><span class="tag"><</span><span class="tag-name">div</span><span> </span><span class="attribute">class</span><span>=</span><span class="attribute-value">"in"</span><span class="tag">></span><span>昵称: </span></li>
<li class=""
发表评论
-
JSP使用Application 对象
2007-01-01 15:26 6026在前一篇里我们讲了在JSP 中使用session 来保存每个用 ... -
Servlet入门
2006-12-29 13:13 4222什么是servlets 明白Servlet API以及与CG ... -
J2EE应用中与Oracle数据库的连接
2006-12-29 13:11 3425J2EE应用中与Oracle数据库的连接 在J2EE应用程序开 ... -
JSP数据库连接池的必要性(转)
2006-12-29 12:36 3992最近我作了数据库JSP的 ... -
oracle之CLOB处理完整版
2006-12-29 11:25 2456/** * *操作oracle数据库的CLOB字段,包括读和写 ... -
StringTokenizer类的使用方法
2006-12-29 11:10 58136StringTokenizer:字符串分隔解析类型 属于:ja ... -
javax.servlet基本类和接口
2006-12-29 10:41 2660基本类和接口 一、javax.servlet.Servlet ... -
JSP于Oracle的完美连接
2006-12-28 19:06 1912Oracle是目前国际上最为流行的关系型对象数据库,已经成为大 ... -
JSP的几种数据库连接<转载>
2006-12-28 09:57 1674现在有好多初学 jsp 的网友经常会问数据库怎么连接啊,怎么老 ... -
返回时间——Bean
2006-12-21 10:53 1238package QueryBean; import java. ... -
中文处理——Bean
2006-12-21 10:07 1179package QueryBean; import java. ... -
分页显示——Bean
2006-12-21 10:06 1246package QueryBean; public class ... -
连接SQLServer——Bean
2006-12-21 10:05 1617package QueryBean; import java. ...
相关推荐
【jsp+ajax聊天室】是一种基于JavaServer Pages (JSP) 和 Asynchronous JavaScript and XML (AJAX) 技术实现的在线实时交流平台。JSP是服务器端的技术,用于生成动态网页,而AJAX则是一种在不刷新整个页面的情况下与...
基于JSP+Ajax+MyEclipse 2015 Java聊天室软件源码+说明文档 通过本课程设计的实践及其前后的准备与总结,复习、领会、巩固和运用软件工程课堂上所学的软件开发方法和知识,以此来完成Java聊天室的分析、设计、编码、...
实现JSP + AJAX聊天室的关键技术点包括: 1. **AJAX请求**:使用JavaScript的XMLHttpRequest对象发起AJAX请求,向服务器发送用户输入的信息,获取服务器返回的新消息。 2. **JSON数据交换**:通常,服务器会将接收...
【JSP+AJAX华丽界面聊天室】是一个利用Java服务器页面(JSP)技术和异步JavaScript及XML(AJAX)技术构建的实时交互系统。它以其美观的英文界面和实用性吸引了用户。在这个项目中,我们将深入探讨JSP与AJAX在创建...
【jsp+ajax 无刷新聊天室】是一种基于JavaServer Pages(JSP)技术和Ajax(Asynchronous JavaScript and XML)技术实现的在线实时交流平台。在这个聊天室中,用户无需手动刷新页面即可实时查看新消息,提高了用户...
JSP+AJAX开发的网络聊天室,川大学生的毕业设计作品,配置好JSP环境就可以运行。用到了Ajax、struts、spring等,用PostgreSQL实现的,但是在平台上转换很简单,只需要修改application.xml里面的数据库源便可,希望对...
【标题】:“一个简单的jsp聊天室(ajax技术)” 在这个项目中,我们探索了一个基于JSP和AJAX技术实现的简单聊天室。JSP(JavaServer Pages)是用于创建动态网页的技术,它允许开发者在HTML代码中嵌入Java代码,...
JASChatWeb 网页聊天室 1.0版--群聊+私聊+贴图 预览 http://ww1.sinaimg.cn/large/560ce489gw1dhm3ju5uxgj.jpg 经过多人 多浏览器测试,效果良好 实现了各种聊天常用功能 (1)群聊 (2)私聊 私聊窗口可拖动关闭 ...
【Jsp+Ajax 在线聊天室】是一款使用Java技术栈,结合JSP和Ajax实现的简单在线交流平台。这个项目适合初学者进行实践,以增强对Web开发的理解,特别是对于那些正在学习Java的大一大二学生而言,是理想的实训项目。在...
【jsp无刷新聊天室(jsp+ajax)】项目是一个典型的Web应用示例,它利用了JavaServer Pages(JSP)技术和Ajax(异步JavaScript和XML)来实现一个无需页面刷新的实时聊天功能。在这个项目中,用户可以在聊天室中发送...
【JSP+AJAX华丽界面聊天室】是一个利用JavaServer Pages(JSP)技术和AJAX(Asynchronous JavaScript and XML)动态网页技术构建的实时交互应用。在这个项目中,开发人员选择了jQuery作为AJAX的框架,因为jQuery简化...
**JSP+Application聊天室详解** 在Web开发领域,构建实时交流平台如聊天室是一项常见的需求。本项目“JSP+Application聊天室”提供了一个基于Java Server Pages (JSP) 技术和Application对象实现的实例,让我们深入...
- **index.jsp**:聊天室的主页面,可能包含AJAX调用的JavaScript代码以及用户界面元素。 - **ChatServlet.java**或类似的Java类:处理AJAX请求,如接收新消息、发送消息等。 - **MessageBean.java**:可能是一个...
综上所述,"ajax无刷新聊天室源码--jsp版"涵盖了Ajax技术、JSP编程、Servlet交互、数据库操作等多个核心知识点,对于学习JavaWeb开发和理解前后端交互机制有着重要的实践意义。通过深入研究这个项目,开发者不仅可以...
【Ajax聊天室】是一个基于Java Web技术实现的简单交互式应用,主要利用了Servlet、JSP和Ajax技术。这个小例子展示了如何通过Ajax实现在不刷新整个页面的情况下更新内容,提供了一个基本的在线聊天功能。 1. **...
在聊天室中,JSP主要负责处理来自客户端的Ajax请求,执行业务逻辑,如验证用户身份、存储或检索聊天记录。JSP还可以动态生成HTML代码,将接收到的新消息插入到聊天窗口,保持页面的实时更新。 MySQL是一个流行的...