導航:首頁 > 源碼編譯 > jsp在線聊天室源碼

jsp在線聊天室源碼

發布時間:2022-07-12 17:13:38

1. 求網路聊天室源碼,用JSP或Servlet都行

用ajax和jsp寫的,可以實現無刷新頁面顯示聊天記錄js/js.js文件varnbsp;obj;varnbsp;getId=document.getElementById;functionnbsp;objXMLHttp(){nbsp;nbsp;nbsp;nbsp;varnbsp;XmlHttpObjnbsp;=nbsp;false;nbsp;nbsp;nbsp;nbsp;if(window.ActiveXObject)nbsp;nbsp;nbsp;nbsp;{nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;XmlHttpObjnbsp;=nbsp;newnbsp;ActiveXObject(「MSXML2.XMLHTTP.3.0「);nbsp;nbsp;nbsp;nbsp;}nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;elsenbsp;ifnbsp;(window.XMLHttpRequest)nbsp;nbsp;nbsp;nbsp;{nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;XmlHttpObjnbsp;=nbsp;newnbsp;XMLHttpRequest();nbsp;nbsp;nbsp;nbsp;}nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;returnnbsp;XmlHttpObj;}functionnbsp;sendMsg(auto){nbsp;obj=objXMLHttp();nbsp;if(!auto)//nbsp;{nbsp;nbsp;varnbsp;myContentnbsp;=nbsp;getId(「myText「).value;nbsp;nbsp;if(myContentnbsp;!=nbsp;「「)nbsp;nbsp;{nbsp;nbsp;nbsp;if(obj)nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;{nbsp;nbsp;nbsp;nbsp;obj.onreadystatechangenbsp;=nbsp;addChat;nbsp;nbsp;nbsp;nbsp;obj.open(「POST「,「do.jsp「,nbsp;true);nbsp;nbsp;nbsp;nbsp;obj.setRequestHeader(「Content-Type「,「application/x-www-form-urlencoded;「);nbsp;nbsp;nbsp;nbsp;nbsp;obj.send(「myContent=「nbsp;+nbsp;myContent);nbsp;nbsp;nbsp;nbsp;getId(「myText「).value=「「;nbsp;nbsp;nbsp;nbsp;getId(「myText「).focus();nbsp;nbsp;nbsp;nbsp;Scroll();nbsp;nbsp;nbsp;nbsp;nbsp;nbsp;}nbsp;nbsp;}nbsp;nbsp;elsenbsp;nbsp;{nbsp;nbsp;nbsp;alert(「nbsp;(*^__^*)nbsp;你不告訴我們,我們怎麼知道你們保持沉默呢「);nbsp;nbsp;nbsp;getId(「myText「).value=「保持沉默「;nbsp;nbsp;nbsp;getId(「myText「).focus();nbsp;nbsp;}nbsp;}nbsp;else//nbsp;{nbsp;nbsp;if(obj)nbsp;nbsp;{nbsp;nbsp;nbsp;obj.onreadystatechangenbsp;=nbsp;addChat;nbsp;nbsp;nbsp;obj.open(「POST「,「do.jsp「,nbsp;true);nbsp;nbsp;nbsp;obj.setRequestHeader(「Content-Type「,「application/x-www-form-urlencoded;「);nbsp;nbsp;nbsp;nbsp;obj.send(null);nbsp;nbsp;nbsp;Scroll();nbsp;nbsp;}nbsp;}}functionnbsp;addChat()//添加聊天記錄{nbsp;varnbsp;docnbsp;=nbsp;「「;nbsp;if(obj.readyStatenbsp;==nbsp;4nbsp;amp;amp;nbsp;obj.statusnbsp;==nbsp;200)nbsp;{nbsp;nbsp;doc=obj.responseText;nbsp;nbsp;if(docnbsp;!=nbsp;「「)nbsp;nbsp;{nbsp;nbsp;nbsp;getId(「says「).value=doc;nbsp;nbsp;}nbsp;}}functionnbsp;getChatContent(){nbsp;tnbsp;=nbsp;setInterval(『sendMsg(true)『,800);}functionnbsp;quickSend(){nbsp;nbsp;if(getId(「sendType「).value==「ctrlEnter「)nbsp;{nbsp;nbsp;if(window.event.ctrlKeyamp;amp;window.event.keyCode==13)nbsp;nbsp;{nbsp;nbsp;nbsp;sendMsg(false);nbsp;nbsp;}nbsp;}nbsp;elsenbsp;if(getId(「sendType「).value==「enterKey「)nbsp;{nbsp;nbsp;if(window.event.keyCode==13)nbsp;nbsp;{nbsp;nbsp;nbsp;sendMsg(false);nbsp;nbsp;}nbsp;}}functionnbsp;loginConfirm(){nbsp;if(window.event.keyCode==13)nbsp;{nbsp;nbsp;checkUser();nbsp;}}functionnbsp;checkUser(){nbsp;if(getId(「userName「).value==nullnbsp;||nbsp;getId(「userName「).value=

2. 求jsp web 聊天室源碼

點這里免費申請聊天室!國外的沒有任何限制!自建聊天室!自己當房主

http://www.sasahongkong.com/paltalk/

3. JSP聊天室調試

源碼是很多書籍里都有的,你所謂的不會測試是不是不知道怎麼在伺服器中運行呢?
看一下關於tomcat的書籍。
(下載tomcat 將源碼放在指定目錄,啟動tomcat 在地址欄輸入http://localhost:8080/指定目錄/jsp聊天室首頁.jsp)

4. 速求用java語言寫聊天室的源代碼

【ClientSocketDemo.java 客戶端Java源代碼】

import java.net.*;
import java.io.*;
public class ClientSocketDemo
{
//聲明客戶端Socket對象socket
Socket socket = null;

//聲明客戶器端數據輸入輸出流
DataInputStream in;
DataOutputStream out;

//聲明字元串數組對象response,用於存儲從伺服器接收到的信息
String response[];

//執行過程中,沒有參數時的構造方法,本地伺服器在本地,取默認埠10745
public ClientSocketDemo()
{
try
{
//創建客戶端socket,伺服器地址取本地,埠號為10745
socket = new Socket("localhost",10745);

//創建客戶端數據輸入輸出流,用於對伺服器端發送或接收數據
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());

//獲取客戶端地址及埠號
String ip = String.valueOf(socket.getLocalAddress());
String port = String.valueOf(socket.getLocalPort());

//向伺服器發送數據
out.writeUTF("Hello Server.This connection is from client.");
out.writeUTF(ip);
out.writeUTF(port);

//從伺服器接收數據
response = new String[3];
for (int i = 0; i < response.length; i++)
{
response[i] = in.readUTF();
System.out.println(response[i]);
}
}
catch(UnknownHostException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}

//執行過程中,有一個參數時的構造方法,參數指定伺服器地址,取默認埠10745
public ClientSocketDemo(String hostname)
{
try
{
//創建客戶端socket,hostname參數指定伺服器地址,埠號為10745
socket = new Socket(hostname,10745);
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());

String ip = String.valueOf(socket.getLocalAddress());
String port = String.valueOf(socket.getLocalPort());

out.writeUTF("Hello Server.This connection is from client.");
out.writeUTF(ip);
out.writeUTF(port);

response = new String[3];
for (int i = 0; i < response.length; i++)
{
response[i] = in.readUTF();
System.out.println(response[i]);
}
}
catch(UnknownHostException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}

//執行過程中,有兩個個參數時的構造方法,第一個參數hostname指定伺服器地址
//第一個參數serverPort指定伺服器埠號
public ClientSocketDemo(String hostname,String serverPort)
{
try
{
socket = new Socket(hostname,Integer.parseInt(serverPort));
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());

String ip = String.valueOf(socket.getLocalAddress());
String port = String.valueOf(socket.getLocalPort());

out.writeUTF("Hello Server.This connection is from client.");
out.writeUTF(ip);
out.writeUTF(port);

response = new String[3];
for (int i = 0; i < response.length; i++)
{
response[i] = in.readUTF();
System.out.println(response[i]);
}
}
catch(UnknownHostException e){e.printStackTrace();}
catch(IOException e){e.printStackTrace();}
}

public static void main(String[] args)
{
String comd[] = args;
if(comd.length == 0)
{
System.out.println("Use localhost(127.0.0.1) and default port");
ClientSocketDemo demo = new ClientSocketDemo();
}
else if(comd.length == 1)
{
System.out.println("Use default port");
ClientSocketDemo demo = new ClientSocketDemo(args[0]);
}
else if(comd.length == 2)
{
System.out.println("Hostname and port are named by user");
ClientSocketDemo demo = new ClientSocketDemo(args[0],args[1]);
}
else System.out.println("ERROR");
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

【ServerSocketDemo.java 伺服器端Java源代碼】

import java.net.*;
import java.io.*;
public class ServerSocketDemo
{
//聲明ServerSocket類對象
ServerSocket serverSocket;

//聲明並初始化伺服器端監聽埠號常量
public static final int PORT = 10745;

//聲明伺服器端數據輸入輸出流
DataInputStream in;
DataOutputStream out;

//聲明InetAddress類對象ip,用於獲取伺服器地址及埠號等信息
InetAddress ip = null;

//聲明字元串數組對象request,用於存儲從客戶端發送來的信息
String request[];

public ServerSocketDemo()
{
request = new String[3]; //初始化字元串數組
try
{
//獲取本地伺服器地址信息
ip = InetAddress.getLocalHost();

//以PORT為服務埠號,創建serverSocket對象以監聽該埠上的連接
serverSocket = new ServerSocket(PORT);

//創建Socket類的對象socket,用於保存連接到伺服器的客戶端socket對象
Socket socket = serverSocket.accept();
System.out.println("This is server:"+String.valueOf(ip)+PORT);

//創建伺服器端數據輸入輸出流,用於對客戶端接收或發送數據
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());

//接收客戶端發送來的數據信息,並顯示
request[0] = in.readUTF();
request[1] = in.readUTF();
request[2] = in.readUTF();
System.out.println("Received messages form client is:");
System.out.println(request[0]);
System.out.println(request[1]);
System.out.println(request[2]);

//向客戶端發送數據
out.writeUTF("Hello client!");
out.writeUTF("Your ip is:"+request[1]);
out.writeUTF("Your port is:"+request[2]);
}
catch(IOException e){e.printStackTrace();}
}
public static void main(String[] args)
{
ServerSocketDemo demo = new ServerSocketDemo();
}
}

5. JSP聊天室源碼下載以及相關問題

網上N多的聊天室框架模板

用戶狀態在資料庫中給他一個狀態欄位
寫一個當前列表方法 其中判斷當前狀態

最後個問題沒弄明白要干什麼

6. 求jsp web 聊天室源碼或者 jsp web即時通訊工具.能聊天.在網頁中.源碼. .

我現在就有一個這樣的東西。。
做的很簡單,其實是自己練習寫一個購物網站 裡面加的一個聊天室

7. 給個JSP聊天室的源代碼 要好使的 最好是JSP + SERVLET的

轉載的
tw-sack.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
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
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
<%@ 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
<!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">昵稱:
<input class="names" name="named" type="text" />
<span id="inputput" class="inputput" onmouseover="overInput(this)" onmouseout="outInput(this)">
<input class="inputs" name="content" type="text" title="提交對話
快捷鍵:Enter或Ctrl + Enter
清除
快捷鍵:Ctrl + Delete" /><input class="left" type="button" onmouseover="lrover(this)" value=" " onmouseout="lrout(this)" onclick="preChat();" title="向前一條對話記錄
快捷鍵:↑" />
<input class="right" onmouseover="lrover(this)" type="button" value=" " onmouseout="lrout(this)" onclick="nextChat();" title="向後一條對話記錄
快捷鍵:↓" />
<input id="btn" class="btn" type="image" src="images/rest.gif" onmouseover="overBtn(this)" onmouseout="outBtn(this)" onclick="doUsingPost();" title="提交對話
快捷鍵:Enter或Ctrl + Enter" />
</span>
<span id="errors"></span>
</div>
</body>
</html>

本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/frankrade/archive/2008/07/23/2699737.aspx

8. jsp如何實現簡單的在線聊天功能

先做一個用戶交流界面 參考代碼 你可以參考<body>裡面的關鍵代碼request.getContextPath();

<head>

<title></title>

</head>

<body>
<form action="servlet/serverMyJsp" method="post">
<textarea rows="20" cols="50" ><%=application.getAttribute("message") %></textarea><br>
<input type="text" name="message">
<input type="submit" value="發送 ">
</form>
</body>
</html>
再做一個程序來處理客戶的交流信息可以參考dopost()方法里的代碼
package server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class serverMyJsp extends HttpServlet {

public serverMyJsp() {
super();
}

public void destroy() {
super.destroy();

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
response.setContentType("text/html");
PrintWriter out = response.getWriter();

}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
response.setCharacterEncoding("gbk");
request.setCharacterEncoding("gbk");
//String demo=request.getParameter("message");
// String str=new String(demo.getBytes("Iso-885-1"),"gbk()");
ServletContext sc=this.getServletContext();
String uname=(String) request.getSession().getAttribute("aa");
System.out.println(uname);
String amessage=(String) sc.getAttribute("message");
sc.setAttribute("message", amessage+uname+"說:"+request.getParameter("message")+"\r\n");
response.sendRedirect("../MyJsp.jsp");

}

public void init() throws ServletException {
}

}

9. JSP實現簡單聊天室的問題

改成下面的樣子:
<%@ page language="java" pageEncoding="GBK"%>
<html>
<head>
<title>My JSP 'lab.jsp' starting page</title>
</head>

<body>
<%
if(application.getAttribute("chat")!=null)
{ if(request.getParameter("mywords")!=null)
{ String mywords=request.getParameter("mywords");
mywords=(String)application.getAttribute("chat")+"<br>"+mywords;
application.setAttribute("chat",mywords);
out.print((String)application.getAttribute("chat"));
}
}else{
application.setAttribute("chat","");
}
%>
<form action="a1.jsf" method="post">
<input type="text" size="30" name="mywords" value="我喜歡聊天">
<input type="submit" name="sumbit" value="提交">
</form>
</body>
</html>
1.要用post提交,否則中文亂碼
2.out.print((String)application.getAttribute("char")); 這句你寫錯了,應該是chat不是char
3.你第一次運行的時候application.getAttribute("chat")肯定是空的,是空的話你又什麼都不作,下次還是空的呀

10. 誰有網頁在線交流的源代碼,jsp的,就是像旺旺那樣的,可以在線交流的軟體代碼,網頁上的

我簡單的寫過類似的代碼,可以實現聊天,但是還需完善,你有興趣的話我可以給你源代碼,但是得給分喲

閱讀全文

與jsp在線聊天室源碼相關的資料

熱點內容
資金回頭選股源碼 瀏覽:252
dz宏命令 瀏覽:353
蟻群演算法實現一維優化代碼 瀏覽:319
伺服器釋放有什麼用 瀏覽:390
解壓包子洗了變粘了怎麼辦 瀏覽:830
635除以三十的簡便演算法 瀏覽:637
樂高ev3編程軟體安卓 瀏覽:337
u盤加密軟體費用 瀏覽:263
中國程序員年死亡率 瀏覽:840
尚德app發帖從哪裡刪除 瀏覽:801
哪裡有學中國象棋的app 瀏覽:115
虛擬機如何編譯bin 瀏覽:831
文件夾藍屏是怎麼回事 瀏覽:641
奧特佳壓縮機日產軒逸 瀏覽:581
隨申辦app在哪裡下載 瀏覽:879
哪裡下載千圖app 瀏覽:724
php打碼嵌入html文檔 瀏覽:461
java如何彈出文件夾選擇框選擇文件路徑 瀏覽:539
saveaspdf的插件 瀏覽:25
電腦文件夾右鍵點擊總是未響應 瀏覽:6