ajax,jsp,java的web应用程序(转)

web端ajax,java,jsp流程图

先来写个.js,叫webask.js

/**
* Send the data to server
*/
function XmlHttpSend(url, method, params, asyn)
{
var headers = new Array(
new Array("Content-Type", "application/x-www-form-urlencoded;charset=GB2312"), //multipart/form-data
new Array("Connection", "Keep-Alive"),
new Array("Pragma", "no-cache"),
new Array("Cache-Control", "no-cache")
);

return XmlHttpSendEx(url, method, params, asyn, headers);
}

function XmlHttpSendEx(url, method, params, asyn, headers)
{
var objXMLHTTP = null;
var i, result = null, bie = true;;

if (window.XMLHttpRequest)
{
bie = false;
objXMLHTTP = new XMLHttpRequest();
}
else
{
var MSXML = new Array(‘MSXML2.XMLHTTP.5.0‘, ‘MSXML2.XMLHTTP.4.0‘, ‘MSXML2.XMLHTTP.3.0‘, ‘MSXML2.XMLHTTP‘, ‘Microsoft.XMLHTTP‘);
for(var i = 0; i < MSXML.length; i ++)
{
try
{
objXMLHTTP = new ActiveXObject(MSXML[i]);
break;
}
catch(e)
{
}
}
}

//compose the parameters
var strparam = null;
if(params != null)
{
for(i = 0; i < params.length; i++)
{
var tmp = params[i];
if(typeof(tmp) == ‘object‘ && (tmp instanceof Array) && tmp.length >= 2)
{
if(strparam == null)
{
strparam = tmp[0] + "=" + tmp[1];
}
else
{
strparam += "&" + tmp[0] + "=" + tmp[1];
}
}
}
}

if(strparam != null)
{
if(method == "GET")
{
if(url.indexOf("?") == -1)
{
url += "?" + strparam;
}
else
{
url += "&" + strparam;
}
}
}

objXMLHTTP.open(method, url, false);

//判断headers是否是一个对象
if(headers != null && typeof(headers) == ‘object‘ && (headers instanceof Array))
{
for(i = 0; i < headers.length; i++)
{
var tmp = headers[i];
if(typeof(tmp) == ‘object‘ && (tmp instanceof Array) && tmp.length >= 2)
{
objXMLHTTP.setRequestHeader(tmp[0], tmp[1]);
}
}
}

if(bie)
{
objXMLHTTP.onreadystatechange=function()
{
if (objXMLHTTP.readyState == 4)
{
result = objXMLHTTP.responseText;
}
}
}

if(method == "POST")
{
objXMLHTTP.setRequestHeader("Content-length", strparam.length);
objXMLHTTP.send(strparam);
}
else
{
objXMLHTTP.send(null);
}

if(!bie)
{
result = objXMLHTTP.responseText;
}

return result;
}

//以上是ajax完毕

function getNowTime()
{
var now=new Date();
var year=now.getFullYear();
var month=now.getMonth();
var day=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();

return (year + ‘-‘ + month + ‘-‘ + day + ‘ ‘ + hour + ‘:‘ + minute + ‘:‘ + second);
}

function ReplaceAll(strOrg,strFind,strReplace)
{
var index = 0;
while(strOrg.indexOf(strFind,index) != -1)
{
strOrg = strOrg.replace(strFind,strReplace);
index = strOrg.indexOf(strFind,index);
}
return strOrg
}

function trim(str)
{
if(str == null) return "" ;

while(str.charAt(0) == ‘ ‘ || str.charAt(0) == ‘\r‘ || str.charAt(0) == ‘\n‘ )
{
str = str.substring(1,str.length);
}

while(str.charAt(str.length-1) == ‘ ‘ || str.charAt(str.length-1) == ‘\r‘ || str.charAt(str.length-1) == ‘\n‘)
{
str = str.substring(0,str.length-1);
}

return str ;
}
//Get the point of control
function getPos(el,sProp)
{
var iPos = 0;
while (el != null)
????{
iPos += el["offset" + sProp];
el = el.offsetParent;
}
return iPos;
}

//Show layer
function showLayer(el, m, bshow)
{
if(bshow && m)
{
m.style.left = getPos(el,"Left");
m.style.top = getPos(el,"Top") + el.offsetHeight;
m.style.display = ‘‘;
}
else m.style.display = ‘none‘;

cmlayer = m;
}

var faceimages;
function loadFace()
{
faceimages = new Array()
faceimages[0] = new Array("/:o", "001.jpg");
faceimages[1] = new Array("/:~", "002.jpg");
faceimages[2] = new Array("/:&", "003.jpg");
faceimages[3] = new Array("/:|", "004.jpg");
faceimages[4] = new Array("/8-)", "005.jpg");
faceimages[5] = new Array("/:<", "006.jpg");
faceimages[6] = new Array("/:$", "007.jpg");
faceimages[7] = new Array("/:X", "008.jpg");
faceimages[8] = new Array("/:Z", "009.jpg");
faceimages[9] = new Array("/:‘(", "010.jpg");
faceimages[10] = new Array("/:-", "011.jpg");
faceimages[11] = new Array("/:@", "012.jpg");
faceimages[12] = new Array("/:P", "013.jpg");
faceimages[13] = new Array("/:D", "014.jpg");
faceimages[14] = new Array("/:)", "015.jpg");
faceimages[15] = new Array("/:(", "016.jpg");
faceimages[16] = new Array("/:+", "017.jpg");
faceimages[17] = new Array("/:#", "018.jpg");
faceimages[18] = new Array("/:Q", "019.jpg");
faceimages[19] = new Array("/:T", "020.jpg");
faceimages[20] = new Array("/:!", "021.jpg");
faceimages[21] = new Array("/:L", "022.jpg");
faceimages[22] = new Array("/:>", "023.jpg");
faceimages[23] = new Array("/:*", "024.jpg");
faceimages[24] = new Array("/<I>", "025.jpg");
faceimages[25] = new Array("/<PI>", "026.jpg");
faceimages[26] = new Array("/<pig>", "027.jpg");
faceimages[27] = new Array("/<cat>", "028.jpg");
faceimages[28] = new Array("/<dog>", "029.jpg");
faceimages[29] = new Array("/<hug>", "030.jpg");
faceimages[30] = new Array("/<coffee>","031.jpg");
faceimages[31] = new Array("/<eat>", "032.jpg");
faceimages[32] = new Array("/<pill>", "033.jpg");
faceimages[33] = new Array("/<rose>", "034.jpg");
faceimages[34] = new Array("/<fade>", "035.jpg");
faceimages[35] = new Array("/<kiss>", "036.jpg");
faceimages[36] = new Array("/<heart>", "037.jpg");
faceimages[37] = new Array("/<break>", "038.jpg");
faceimages[38] = new Array("/<meeting>","039.jpg");
faceimages[39] = new Array("/<gift>", "040.jpg");
faceimages[40] = new Array("/<phone>", "041.jpg");
faceimages[41] = new Array("/<time>", "042.jpg");
faceimages[42] = new Array("/:;", "043.jpg");
faceimages[43] = new Array("/<tv>", "044.jpg");
faceimages[44] = new Array("/<sun>", "045.jpg");
faceimages[45] = new Array("/<moon>", "046.jpg");
faceimages[46] = new Array("/<strong>","047.jpg");
faceimages[47] = new Array("/<weak>", "048.jpg");
faceimages[48] = new Array("/<share>", "049.jpg");
faceimages[49] = new Array("/<^>", "050.jpg");

for(i = 0; i < faceimages.length; i++)
{
var aimage = new Image();
aimage.src = "/images/faces/" + faceimages[i][1];
}
}

function changeFace(facesdiv, thetext, face)
{
thetext.value += face;
showLayer(null, facesdiv, false);
thetext.focus();
}

function displayFace(facesdiv, thetext)
{
var s = "";
for(i = 0; i < faceimages.length; i++)
{
s += "<img src=\"" + "/images/faces/" + faceimages[i][1] + "\" width=\"20\" height=\"20\" border=\"0\" alt=\"" + faceimages[i][0] + "\" style=\"cursor:hand\" onClick=\"changeFace(" + facesdiv + ", " + thetext + ", this.alt)\">";
if((i + 1) % 10 == 0) s += "<br>";
}
var f = document.getElementById(facesdiv);
//alert(s);
f.innerHTML = s;
}

function replaceFace(s)
{
for(i = 0; i < faceimages.length; i++)
{
s = ReplaceAll(s, faceimages[i][0], "<img src=\"" + "/images/faces/" + faceimages[i][1] + "\" width=\"20\" height=\"20\" border=\"0\">");
}
return s;
}

随时问界面:chat.jsp
<%@ page language="java" pageEncoding="gb2312" %>
<%@ page import="java.lang.*" %>
<%@ page import="ebs.domain.mdl.*" %>
<%@ page import="java.util.*"%>

<%
Integer ioImnum = (Integer) request.getAttribute("imnum");
int iImnum = ioImnum.intValue();

Integer ioRandid = (Integer) request.getAttribute("randid");
int iRandid = ioRandid.intValue();

WebAskUser askUser = (WebAskUser) request.getAttribute("webaskuser");

String logo_ent = (String)request.getAttribute("logo_ent");
String logo_user = (String)request.getAttribute("logo_user");

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=request.getAttribute("title")%></title>
<link href="/webask/ask.css" rel="stylesheet" type="text/css">
<script language="javascript" src="/webask/webask.js"></script>
<script language="javascript">
<!--
var clspin = true;
var wa_g_is_send_file = false;

function getLen(s)
{
var len = 0;
for(var i = 0; i < s.length; i++)
{
if(s.charCodeAt(i) > 127)
{
len +=2;
}
else
{
len ++;
}
}

return len;
}

function sendMsg(frm)
{
var s = trim(frm.content.value);
if(s == "")
{
alert("不能发送空消息!");
frm.content.value = ‘‘;
return;
}

if(getLen(s) > 200)
{
alert("消息大小不能大于200个字符!");
return;
}

var content = ‘‘;
for(i = 0; i < s.length; i++)
{
content += ‘0x‘ + s.charCodeAt(i);
}

document.recvfrm.content.innerHTML += "<font color=\"#CC0000\">您说 " + getNowTime() + ":</font><br>&nbsp;&nbsp;";
s = ReplaceAll(ReplaceAll(s, "\r\n", "<br>")," ", "&nbsp;");
s = replaceFace(s);
document.recvfrm.content.innerHTML += s + "<br>";
frm.content.value = ‘‘;

var params = new Array();
params[0] = new Array("module", "sendmsg");
params[1] = new Array("imnum", frm.imnum.value);
params[2] = new Array("randid", frm.randid.value);
params[3] = new Array("content", content);
result = XmlHttpSend("/webask", "POST", params, false);
//alert(result);
if (result != null && (result == "$SMS_" || result == "$LEAVE_"))
{
clspin = false;
frm.content.value = ‘‘;

if(result=="$SMS_")
{
window.location = "webask?module=smswords&imnum=<%=iImnum%>";
}
else
{
window.location = "webask?module=chat&imnum=<%=iImnum%>";
}
}
else if(result == null || result == "" || result.indexOf("200") != 0)
{
if(result.indexOf("444") == 0) result = "原因:没有权限" ;
if(result.indexOf("400") == 0) result = "原因:随时问过期或被禁用" ;
document.recvfrm.content.innerHTML += "<font color=\"#FF0000\">发送失败(" + result + ")</font><br>&nbsp;&nbsp;<font color=\"#CC0000\">" + s + "</font><br>";
}

return;
}

function contentKeyUp(frm, events)
{
var o_rtnsend = document.getElementById("rtnsend");
if(events.keyCode == 13 && o_rtnsend.checked)
{
sendMsg(frm);
}
}

function waSendFile(thefrm)
{
if(thefrm.filename.value == "")
{
alert(‘请选择要上传的文件!‘);
return false;
}
var filename = thefrm.filename.value;
filename = filename.substr(filename.lastIndexOf("\\") + 1);
document.recvfrm.content.innerHTML += "<font color=\"#FF0000\">文件(" + filename + ")发送中...</font><br>";

filewin(false);
wa_g_is_send_file = true;
return true;
}

function pointwin()
{
closeim();
if(clspin)
{
window.open(‘webask?module=point&onlineid=<%=request.getAttribute("onlineid")%>&webid=<%=request.getAttribute("webid")%>‘,"pointwin","height=240,width=300,toolbar=no,location=no,status=no");
}
}

function closeim()
{
if (window.XMLHttpRequest)
{
http_request = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
http_request.open(‘GET‘, "webask?module=closeim&imnum=<%=iImnum%>&randid=<%=iRandid%>", true);
http_request.send(null);
}

function filewin(b)
{
if(wa_g_is_send_file)
{
document.recvfrm.content.innerHTML += "<font color=\"#FF0000\">文件发送中,请稍候...</font><br>";
return;
}

var fileb = document.getElementById("wa_file_box");
var textb = document.getElementById("wa_text_box");
if(b)
{
textb.style.display = ‘none‘;
fileb.style.display = ‘‘;
}
else
{
fileb.style.display = ‘none‘;
textb.style.display = ‘‘;
}
}

function saveLog()
{
document.slog.log.value = document.recvfrm.content.innerText;
document.slog.submit();
return true;
}

function wsStart()
{
loadFace();
displayFace(‘faces‘, ‘document.frmsend.content‘);
}

function sfFinish(frm_name)
{
var result = document.frames(frm_name).document.body.innerText;

if(result != null && result == "") return;

if(result.indexOf("200") == 0)
{
result = "已发送成功";
}
else if(result.indexOf("504") == 0)
{
result = "发送失败,文件大小不得超过2兆";
}
else
{
result = "发送失败";
}

filename = document.wa_frm_send_file.filename.value;
filename = filename.substr(filename.lastIndexOf("\\") + 1);
document.recvfrm.content.innerHTML += "<font color=\"#FF0000\">文件(" + filename + ")" + result+ "...</font><br>";

wa_g_is_send_file = false;
}
//-->
</script>
</head>

<body leftmargin="0" topmargin="0"
onLoad="wsStart()" onunload="pointwin();" oncontextmenu=‘return false‘ ondragstart=‘return false‘ >
<iframe width="0" height="0" scrolling="no" src="#" frameborder="0" name="wa_frm_file" onLoad="sfFinish(this.name)"></iframe>
<table width="608" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFFFFF">
<div id="head">
<div id="head01">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><span
class="font_blue">您正与<%=askUser.getNickname()%>交谈&nbsp;</span>
</td>
<td align="right">
<%if(logo_ent!=null&&!logo_ent.trim().equals(""))
{%>
<img src="<%=request.getAttribute("logo_ent")%>" height="41" align="right" >
<%}else{%>
&nbsp;
<%}%>
</td>
</tr>
</table>
</div>

<div id="head02">&nbsp;</div>
</div>
</td>
</tr>
</table>
<table width="608" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFFFFF">
<div id="conchat">
<div id="conchat01">
<table width="427" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="32" background="/webask/ask_img/askcontop.jpg">
<span class="font_blue2">&nbsp;&nbsp;&nbsp;&nbsp;<img
src="/webask/ask_img/asktip04.jpg" width="24"
height="24">&nbsp;&nbsp;如果您有任何疑问,也可以点击查看</span><span class="font_blue"><a href="/webask?module=listproblem&entnth=<%=(iImnum/1000)%>" target="_blank">常见问题</a>
</span>
</td>
</tr>
<tr>
<td height="200" valign="top" background="/webask/ask_img/askconbg.jpg">
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0" onClick="showLayer(this, faces, false)">
<tr>
<td>
<font color="#FF0000" style="font-size:12px">请不要关掉对话窗口,不然将无法收到在线客服的回答!</font>
<iframe src="/webask?module=recvchat&imnum=<%=iImnum%>&randid=<%=iRandid%>"
name="mainfrm" id="recvfrm" marginWidth=0 marginHeight=0 width=420
height="182" frameborder="0">
</iframe>
</td>
</tr>
</table>

</td>
</tr>
<tr>
<td><img src="/webask/ask_img/askconbog.jpg" width="427" height="9"></td>
</tr>
</table>
<!-------------------------------------------------------------------------------------------->
<table width="427" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td height="34" align="center" background="/webask/ask_img/askcontop2.jpg" class="font_blue2">
<img src="/webask/ask_img/asktip01.jpg">&nbsp;<a href="#" onClick="saveLog()" style="text-decoration:none">保存对话记录</a>&nbsp;
<img src="/webask/ask_img/asktip02.jpg">&nbsp;
<a href="#" onClick="showLayer(this, faces, true)" style="text-decoration:none">表情</a>&nbsp;
<img src="/webask/ask_img/asktip03.jpg">&nbsp;<a href="#" onclick="filewin(true)" style="text-decoration:none">传送文件</a>&nbsp;
&nbsp;<input type="checkbox" id="rtnsend" checked>回车键发送信息 </td>
</tr>
<tr>
<td height="68" background="/webask/ask_img/askconbg.jpg">
<div id="wa_text_box">
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0" onClick="showLayer(this, faces, false)">
<form method="post" name="frmsend">
<input type="hidden" name="imnum" value="<%=iImnum%>">
<input type="hidden" name="randid" value="<%=iRandid%>">
<tr>
<td width="86%" valign="top" class="font_black">
<textarea name="content" cols="54"
rows="5" class="input_no"
onKeyUp="contentKeyUp(this.form, event)"></textarea>

</td>
<td width="14%" align="right">
<img src="/webask/ask_img/askbut.jpg" width="58" height="45" border="0"
onClick="sendMsg(document.frmsend)"></td>
</tr>
</form>
</table>
</div>
<div id="wa_file_box" style="display:none">
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="0" onClick="showLayer(this, faces, false)">
<form method="post" name="wa_frm_send_file" action="webask?module=sendfile&imnum=<%=iImnum%>&randid=<%=iRandid%>" enctype="multipart/form-data" target="wa_frm_file" onSubmit="return waSendFile(this)">
<tr>
<td width="86%" valign="top" class="font_black">
请选择要上传的文件:<input type="file" name="filename" class="input">
<input type="submit" value="上传" class="input">
<input type="button" value="取消" onClick="filewin(false)" class="input">
<br><span class="font_red">注意:</span>文件大小不得超过2兆;文件类型:zip,rar,doc,txt,gif,jpg,png,ppt,xls。如果文件大,点确定后可能会有停顿感,请耐心等待。
</td>
</tr>
</form>
</table>
</div>
</td>
</tr>
<tr>
<td><img src="/webask/ask_img/askconbog2.jpg" width="427" height="9"></td>
</tr>
<div id="faces"
style="position:absolute;top:10;left:10;width:210;display:none;background-color:#FFFFCC;border:solid black 1px"></div>
</table>
<!------------------------------------------------------------------------------------------>
</div>

<div id="conchat02">
<table width="75%" border="0" align="center" cellpadding="0" cellspacing="0" onClick="showLayer(this, faces, false)">
<tr>
<td><img src="/webask/ask_img/askrtop.jpg" width="146" height="11"></td>
</tr>
<tr>
<td height="330" valign="top" background="/webask/ask_img/askrbg.jpg">
<table width="75%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="<%if(logo_user!=null&&!logo_user.trim().equals(""))out.print(logo_user);else { %>/<%=WebAsk.LOGO_FOLDER%>/<%=WebAskUser.DEFAULT_LOGO%><%}%> " width="130" height="130">
</td>
</tr>
<!-------------------------------------------------------------------------------------->
<tr>
<td bgcolor="#FFFFFF">
<%if(askUser.getDisplay()==WebAskUser.DISPLAY_YES){
Hashtable haUser = (Hashtable)request.getAttribute("htUser");
%>
<span class="font_blue">姓名:</span><span class="font_black"><%out.print((String)haUser.get("lstnam")+(String)haUser.get("fstnam"));%></span><br>
<span class="font_blue">部门:</span><span class="font_black"><%=haUser.get("orgname")%></span><br>
<span class="font_blue">职务:</span><span class="font_black"><%=haUser.get("duty")%></span><br>
<span class="font_blue">地址:</span><span class="font_black"><%=haUser.get("adr")%></span>
<br>
<span class="font_blue">电子邮件:</span><span class="font_black"><a href=" mailto:<%=haUser.get("mail")%>"><%=haUser.get("mail")%></a></span><br>
<%}else{
out.print("&nbsp;");
}%>
<br>
</td>
</tr>
<!------------------------------------------------------------------------------------------>
</table>
</td>
</tr>
<tr>
<td><img src="/webask/ask_img/askrbot.jpg" width="146" height="9"></td>
</tr>
</table>

</div>
</div>
</td>
</tr>
</table>
<table width="608" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#FFFFFF"><img src="/webask/ask_img/askbot.jpg" width="608" height="12"></td>
</tr>
</table>
<form method="post" action="/webask" name="slog">
<input type="hidden" name="module" value="savelog">
<input type="hidden" name="randid" value="<%=iRandid%>">
<input type="hidden" name="log" value="">
</form>
</body>
</html>

接收返回的消息记录:recvchat.jsp(在iframe里显示)

<%@ page language="java" pageEncoding="gb2312" %>
<%@ page import="java.lang.*" %>

<%
Integer ioImnum = (Integer) request.getAttribute("imnum");
int iImnum = ioImnum.intValue();

Integer ioRandid = (Integer) request.getAttribute("randid");
int iRandid = ioRandid.intValue();
String stNickName = (String)request.getAttribute("nickname");
//String stNickName = Integer.toString(iImnum);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<link href="/main.css" rel="stylesheet" type="text/css">
<style type="text/css">
body
{
BACKGROUND-COLOR: #ffffff;
BORDER-BOTTOM: 0px;
BORDER-LEFT: 0px;
BORDER-RIGHT: 0px;
BORDER-TOP: 0px;
COLOR: #666666;
border-color: #006699 #006699 #006699 #006699; font-size: 9pt
margin: 0px;
padding: 0px;
scrollbar-face-color: #DBE3F4;
scrollbar-arrow-color: #668BC7;
scrollbar-track-color: #C8D6EE;
font: 12px/20px ??ì?;
}
</style>
<script language="javascript" src="/webask/webask.js"></script>
<script language="JavaScript">
<!--
var oldscr = 0;
function autoscroll()
{
//alert(document.body.scrollTop + " " + document.body.scrollHeight);
if(oldscr < document.body.scrollHeight)
{
window.scroll(0, document.body.scrollTop + document.body.scrollHeight - oldscr);
oldscr = document.body.scrollHeight;
}
window.setTimeout(‘autoscroll()‘, 200);
}

function recvmsg()
{
var params = new Array();
params[0] = new Array("module", "recvmsg");
params[1] = new Array("imnum", <%=iImnum%>);
params[2] = new Array("randid", <%=iRandid%>);
var result = XmlHttpSend("/webask", "POST", params, false);
if(result != "" && result.indexOf("200 ") == 0)
{
result = result.substr(4);
var buf = result.split("0x");
var s = "";
for(i = 1; i < buf.length; i++)
{
s += String.fromCharCode(parseInt(buf[i], 10));
}
content.innerHTML += "<font color=\"#0033CC\"><%=stNickName%>?μ " + getNowTime() + ":</font><br>&nbsp;&nbsp;";

s = ReplaceAll(s, "\n", "<br>");
s = replaceFace(s);
content.innerHTML += s + "<br>";
if(window.parent)
{
parent.focus();
}
else
{
window.focus();
}
}

window.setTimeout(‘recvmsg()‘, 3000);
}
//-->
</script>
</head>
<body leftmargin="0" topmargin="0" onLoad="loadFace();autoscroll();window.setTimeout(‘recvmsg()‘, 3000);" oncontextmenu=‘return false‘ ondragstart=‘return false‘ >
<div id="content">
<font color="#CC0000"><%=stNickName%>&nbsp;<script language="javascript">document.write(getNowTime())</script>:</font>
<br>
<%=request.getAttribute("welcome")%>
<br>
</div>

</body>
</html>

java执行:WebAskSvl.java
protected void sendMsg(HttpServletRequest oReq, HttpServletResponse oRsp)
{
PrintWriter out = null;
try
{
out = oRsp.getWriter();
}
catch (Exception ex)
{
}

WebAsk webAsk = new WebAsk();
WebAskUser webAskUser = new WebAskUser();
int iImnum = checkWebAskUser(webAsk, webAskUser, oReq, oRsp); //10浣?

String filterResult = filterSpecial(iImnum).trim();
if(!filterResult.equals(""))
{
out.print(filterResult);return;
}
/*if (iImnum == 0) return;*/

if (isMidSmsLeaveWord(webAskUser, oRsp))
{
return;
}

String stRandId = oReq.getParameter("randid");
int iRandid;
try
{
iRandid = Integer.parseInt(stRandId);
}
catch (NumberFormatException e)
{
out.print("500 Error");
return;
}

String stContent = oReq.getParameter("content");
if (stContent == null || "".equals(stContent.trim()))
{
out.print("500 Error");
return;
}

stContent = encode(stContent);
if(AwayTools.getGB2312Length(stContent) > 200)
{
out.print("501 Error");
return;
}

String stArea = oReq.getRemoteAddr();
try
{
long ip = AwayTools.ipToInt(stArea);
if (ip != -1)
{
stArea = IPAddress.queryIPArea(ip);
}
}
catch (SQLException e)
{
}

WebAskLog log = new WebAskLog();
log.setContent(stContent);

log.setDtime(new java.sql.Timestamp(System.currentTimeMillis()));
log.setIp_address(stArea);
log.setWebask_sid(webAsk.getId());
log.setWebask_user_sid(webAskUser.getSid());
log.setFlag(WebAskLog.FLAG_CLIENT);
log.setWeb_id(iRandid);
try
{
WebAskLogMng.save(log);
}
catch (SQLException e)
{
e.printStackTrace();
out.print("502 Error");
return;
}

WebAskManager.send(iImnum, iRandid, stContent);
out.print("200 Successfully");
}

protected void showRecvChat(HttpServletRequest oReq, HttpServletResponse oRsp)
{
WebAsk webAsk = new WebAsk();
WebAskUser webAskUser = new WebAskUser();
int iImnum = checkWebAskUser(webAsk, webAskUser, oReq, oRsp); //10浣?

String filterResult = filterSpecial(iImnum).trim();
if(!filterResult.equals(""))
{
return;
}

/*if (iImnum == 0) return;*/

String stRandId = oReq.getParameter("randid");

int iRandid;
try
{
iRandid = Integer.parseInt(stRandId);
}
catch (NumberFormatException e)
{
this.shwErrMsg("_ERROR_INPUT", oReq, oRsp);
return;
}

oReq.setAttribute("nickname", webAskUser.getNickname());
oReq.setAttribute("welcome", webAskUser.getWelcome());
oReq.setAttribute("randid", new Integer(iRandid));
this.shwPag("/webask/recvchat.jsp", oReq, oRsp);
}

protected void recvMsg(HttpServletRequest oReq, HttpServletResponse oRsp)
{
WebAsk webAsk = new WebAsk();
WebAskUser webAskUser = new WebAskUser();
int iImnum = checkWebAskUser(webAsk, webAskUser, oReq, oRsp); //10浣?

/*String filterResult = filterSpecial(iImnum).trim();
if(!filterResult.equals(""))
{
out.print(filterResult);return;
}*/
if (iImnum == 0) return;

String stRandId = oReq.getParameter("randid");

int iRandid;
try
{
iRandid = Integer.parseInt(stRandId);
}
catch (NumberFormatException e)
{
//this.shwErrMsg("_ERROR_INPUT", oReq, oRsp);
return;
}

String stContent = WebAskManager.recv(iImnum, iRandid);

//System.out.println("Recv: " + iImnum + " " + iRandid + " " + stContent);

PrintWriter out = null;
try
{
out = oRsp.getWriter();
}
catch (Exception ex)
{
}

if (stContent != null && ! stContent.trim().equals(""))
{
String stArea = oReq.getRemoteAddr();
try
{
long ip = AwayTools.ipToInt(stArea);
if (ip != -1)
{
stArea = IPAddress.queryIPArea(ip);
}
}
catch (SQLException e)
{
}

WebAskLog log = new WebAskLog();
log.setContent(stContent);
log.setDtime(new java.sql.Timestamp(System.currentTimeMillis()));
log.setIp_address(stArea);
log.setWebask_sid(webAsk.getId());
log.setWebask_user_sid(webAskUser.getSid());
log.setWeb_id(iRandid);
log.setFlag(WebAskLog.FLAG_WAITER);
log.setWeb_id(iRandid);

try
{
WebAskLogMng.save(log);
}
catch (Exception e)
{
e.printStackTrace();
}
out.print("200 " + decode(stContent));
}
else
{
out.print("404 ");
}

}

时间: 2024-10-18 08:59:52

ajax,jsp,java的web应用程序(转)的相关文章

servlet+jsp+java实现Web应用

servlet+jsp+java实现Web应用 环境: 1,eclipse 2,tomcat3,eclipse tomcat 插件 开发过程: 1,建立一个Dynamic Web Project 2,创建一个欢迎页面 页面可以是jsp/html,我们选择一个jsp页面(放在WebContent内) <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding=

tomcat+java的web程序持续占cpu问题调试

原文出处:http://www.blogjava.net/hankchen 现象: 在tomcat中部署java的web应用程序,过一段时间后出现tomcat的java进程持续占用cpu高达100%,导致web程序访问受阻. 可能原因分析: 可能程序确实在进行数据计算:或程序进入死循环: 解决方法: 1.先用top查看占用cpu的进程id 2.再用ps -ef | grep PID定位具体的进程主体:如是否是tomcat启动的java程序 3.用ps -mp pid -o THREAD,tid,

理解Web应用程序的代码结构和运行原理(3)

1.理解Web应用程序的运行原理和机制 Web应用程序是基于浏览器/服务器模式(也称B/S架构)的应用程序,它开发完成后,需要部署到Web服务器上才能正常运行,与用户交互的客户端是网页浏览器. 浏览器负责显示来自服务器的数据和接受用户的输入数据,也称为"与用户交互":服务器负责处理浏览器的访问请求,并把处理结果(数据或消息)组织成浏览器可以识别的格式文本返回. Web应用程序的主要特点如下: 1)浏览器主动请求服务器资源.在Web应用程序中,一般是浏览器首先向服务器发起访问某个网页或某

MVC在Java Web应用程序中的实现

一.MVC简介 MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码,将业务逻辑聚集到一个部件里面,在改进和个性化定制界面及用户交互的同时,不需要重新编写业务逻辑. Model(模型)是应用程序中用于处理应用程序数据逻辑的部分. 通常模型对象负责在数据库中存取数据. View(视图)是应用程序中处理数据显示的部分. 通常视图是依据模型数据创建的. C

MVC模式在Java web 应用程序的实现

一.MVC简介 MVC(Model-View-Controller)模型-视图-控制器,最早由Trygve Reenskaug在1978年提出,是施乐帕罗奥多研究中心(Xerox PARC)在20世纪80年代为程序语言Smalltalk发明的一种软件架构.MVC模式的目的是实现一种动态的程序设计,使后续对程序的修改和扩展简化,并且使程序某一部分的重复利用成为可能.除此之外,此模式通过对复杂度的简化,使程序结构更加直观.软件系统通过对自身基本部分分离的同时也赋予了各个基本部分应有的功能. Mode

MVC模式在Java Web应用程序中的实现

MVC简介 MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码,将业务逻辑聚集到一个部件里面,在改进和个性化定制界面及用户交互的同时,不需要重新编写业务逻辑.MVC被独特的发展起来用于映射传统的输入.处理和输出功能在一个逻辑的图形化用户界面的结构中. MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创

Java Web学习(1):Web应用程序与Web服务器

一Web应用程序 (1)什么是Web应用程序 应用程序有两种模式C/S.B/S.C/S是客户端/服务器端程序,也就是说这类程序一般独立运行.而B/S就是浏览 器端/服务器端应用程序,这类应用程序一般借助浏览器来运行. Web应用程序一般是B/S模式.Web应用程序首先是应用程序,和用标准的程序语言,如Java.PHP等编写出来 的程序没有什么本质上的不同.然而Web应用程序又有自己独特的地方,就是它是基于Web的,而不是采用传统方法 运行的.换句话说,它是典型的浏览器/服务器架构的产物. 一个W

Java Web学习(4):徒手开发Web应用程序

一Tomcat服务器的目录结构 在开发Web应用程序之前有必要先来介绍一下Tomcat服务器的目录结构. 1)我们打开安装好的Tomcat服务器的安装目录,我的是:E:\Java\develop\apache-tomcat-8.0.36,也就是我们配 置的环境变量CATALINA_HOME的变量值. 我们先来整体的看一下各个目录的描述: 2)bin目录下存放的Windows批处理是重要的,包含着Tomcat服务器的启动与停止,也有一些jar文件,和Tomcat 服务器的运行文件. 3)conf目

Jsp之一 WEB应用程序概述

C/S.B/S应用程序介绍 ?       C/S应用程序介绍 C/S (Client/Server)结构,即客户机和服务器结构.它是常说的胖客户端软件体系结构,通过它可以充分利用两端硬件环境的优势,将任务合理分配到Client端和Server端来实现,降低了系统的通讯开销.目前大多数应用软件系统都是Client/Server形式的两层结构.比如网络游戏就是用C/S模式开发的,想玩网络游戏必须在电脑机client上装上一个客户端软件,而且很多的业务处理都是在客户端上实现的.通常情况下C/S模式对