當前位置:商標查詢大全網 - 彩票開獎 - 求網上聊天室的源碼,用JSP或者Servlet都行。

求網上聊天室的源碼,用JSP或者Servlet都行。

用ajax和jsp寫的,不用刷新頁面就可以顯示聊天記錄js/js.js文件varnbspobjvarnbspgetId = document.getElementById功能nbsp。objXMLHttp(){ nbsp;nbspnbspnbspvarnbspXmlHttpObjnbsp。= nbsp假的;nbspnbspnbspnbsp如果(窗口。ActiveXObject)nbsp。nbspnbspnbsp{ nbspnbspnbspnbspnbspnbspnbspnbspXmlHttpObjnbsp。= nbsp新nbsp。ActiveXObject("MSXML2。xmlhttp . 3.0”);nbspnbspnbspnbsp} nbspnbspnbspnbspnbspnbspelsenbspifnbsp。(窗口。XMLHttpRequest)nbsp。nbspnbspnbsp{ nbspnbspnbspnbspnbspnbspnbspnbspXmlHttpObjnbsp。= nbsp新nbsp。XMLHttpRequest();nbspnbspnbspnbsp} nbspnbspnbspnbspnbspnbsp返回nbsp。XmlHttpObj}功能nbsp。sendMsg(auto){nbsp。obj = objXMLHttp();nbsp如果(!auto)//nbsp;{ nbspnbspvarnbspmyContentnbsp= nbspgetId("myText ")。價值;nbspnbspif(myContentnbsp;!= nbsp》)nbspnbsp{ nbspnbspnbsp如果(obj)nbsp。nbspnbspnbspnbspnbsp{ nbspnbspnbspnbspobj.onreadystatechangenbsp= nbspaddChatnbspnbspnbspnbspobj.open("POST "," do.jsp ",nbsp真);nbspnbspnbspnbspobj . setrequestheader(" Content-Type "," application/x-www-form-urlencoded;");nbspnbspnbspnbspnbspobj . send(" my content = " nbsp;+nbsp;my content);nbspnbspnbspnbspgetId("myText ")。值= " ";nbspnbspnbspnbspgetId("myText ")。焦點();nbspnbspnbspnbsp滾動();nbspnbspnbspnbspnbspnbsp} nbspnbsp} nbspnbspelsenbspnbsp{ nbspnbspnbspalert(" nbsp;(*^__^*)nbsp;如果妳不告訴我們,我們怎麽知道妳會保持沈默?”);nbspnbspnbspGetid ("mytext ")。value = "保持沈默";nbspnbspnbspgetId("myText ")。焦點();nbspnbsp} nbsp} nbspelse//nbsp;{ nbspnbsp如果(obj)nbsp。nbsp{ nbspnbspnbspobj.onreadystatechangenbsp= nbspaddChatnbspnbspnbspobj.open("POST "," do.jsp ",nbsp真);nbspnbspnbspobj . setrequestheader(" Content-Type "," application/x-www-form-urlencoded;");nbspnbspnbspnbspobj . send(null);nbspnbspnbsp滾動();nbspnbsp} nbsp} }功能nbsp。AddChat()//添加聊天記錄{ nbspvarnbsp文檔nbsp。= nbsp"";nbspif(obj . readystatenbsp;= = nbsp4nbspampampnbspobj.statusnbsp= = nbsp200)nbsp。{ nbspnbspdoc = obj.responseTextnbspnbsp如果(docnbsp!= nbsp》)nbspnbsp{ nbspnbspnbspgetId("says ")。value = docnbspnbsp} nbsp} }功能nbsp。getChatContent(){ nbsp;tnbsp= nbspsetInterval('sendMsg(true)',800);}功能nbsp。quickSend(){ nbsp;nbspif(getId("sendType ")。value=="ctrlEnter")nbsp。{ nbspnbspif(window . event . ctrl keyamp;ampwindow . event . key code = = 13)nbsp;nbsp{ nbspnbspnbspsend msg(false);nbspnbsp} nbsp} nbspelsenbspif(getId("sendType ")。value=="enterKey")nbsp。{ nbspnbspif(window . event . key code = = 13)nbsp;nbsp{ nbspnbspnbspsend msg(false);nbspnbsp} nbsp} }功能nbsp。loginConfirm(){ nbsp;if(window . event . key code = = 13)nbsp;{ nbspnbspcheck user();nbsp} }功能nbsp。check user(){ nbsp;if(getId("用戶名")。value==nullnbsp。||nbsp。getId(“用戶名”)。值=