导航:首页 > 源码编译 > 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在线聊天室源码相关的资料

热点内容
喷油螺杆制冷压缩机 浏览:578
python员工信息登记表 浏览:376
高中美术pdf 浏览:160
java实现排列 浏览:512
javavector的用法 浏览:981
osi实现加密的三层 浏览:231
大众宝来原厂中控如何安装app 浏览:913
linux内核根文件系统 浏览:242
3d的命令面板不见了 浏览:525
武汉理工大学服务器ip地址 浏览:148
亚马逊云服务器登录 浏览:524
安卓手机如何进行文件处理 浏览:70
mysql执行系统命令 浏览:929
php支持curlhttps 浏览:142
新预算法责任 浏览:443
服务器如何处理5万人同时在线 浏览:250
哈夫曼编码数据压缩 浏览:424
锁定服务器是什么意思 浏览:383
场景检测算法 浏览:616
解压手机软件触屏 浏览:348