世界因你而精彩  
日历
<2007年6月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
统计
  • 随笔 - 169
  • 文章 - 1
  • 评论 - 138
  • 引用 - 0

导航

常用链接

留言簿(9)

随笔分类(163)

随笔档案(154)

文章档案(1)

新闻档案(1)

相册

收藏夹(1)

个人杂杂

友情链接

自学考试

资料搜索

最新随笔

搜索

  •  

积分与排名

  • 积分 - 358366
  • 排名 - 153

最新评论

阅读排行榜

评论排行榜

 

一个叫随时问的流程,写个总结.
相当长,相信你有耐心看完!哈哈嘻嘻!
先画个流程图吧:


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);

 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 ");
        }

    }

posted on 2007-06-07 15:34 张秀兰 阅读(1164) 评论(1)  编辑  收藏 所属分类: 资料查找
评论:
  • # re: 总结下:ajax,jsp,java的web应用程序:随时问  mymywo Posted @ 2009-06-19 14:53
    学这个学了半天没学懂  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © 张秀兰 Powered by: 博客园 模板提供:沪江博客