好學驛站

          JSP、JAVA、struts、hibernate、spring、eclipse、工作流、電子政務、協(xié)同辦公、J2ME

          頁面嵌入在線聊天 (prototype)

          問題 : 提供給B/S 結構一個實時的運行展現(xiàn)
          解決:?? prototype 的?Ajax.PeriodicalUpdater 更新
          ??????????? prototype 的??? Ajax.Request 語句提交
          ????????????action 語句的組織展現(xiàn)

          http://www.aygfsteel.com/Files/Good-Game/take.rar

          ????沒有l(wèi)ib 大家可以就加 struct 相關 lib 就可以了

          說明:?
          ??????

          <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">
          <html>
          ??
          <head>
          ??????????
          <SCRIPT?language="Javascript"?src="prototype1.5.0.js"></SCRIPT>
          ??
          </head>
          ??
          ??
          <body?onload="Said()">?
          ??????
          <INPUT?id='name1'?type="text"?size="10"?value="請輸入名字"?onfocus="if($('name1').value=='請輸入名字')?$('name1').innerText=''?"?/>
          ??????
          <INPUT?id='text1'?type="text"?onkeydown="if(event.keyCode==13){event.keyCode=0;?onb();}"/>
          ??????
          <INPUT?id='button1'?type="button"?value="test"?onclick='onb()'?/>
          ??
          </body>
          ??
          <div?id='div1'/>
          </html>
          <script?type="text/javascript"??>
          ??????? //語句異步提交給服務器 Ajax.Request
          ????
          function?onb(){?????????????????????????????????????????
          ??????
          if($('name1').value=='請輸入名字'?||?$('name1').value==''){
          ??????????window.alert('請輸入名字');
          ??????????
          return?
          ??????}

          ??????
          ??????
          var?url?=?'http://192.168.1.130:7000/xxs/mySaid.do?name='+$F('name1')+'&take='+$F('text1');????????????????
          ??????new?Ajax.Request(
          ????????url,
          ????????
          {
          ????????????method:?'get',
          ????????????onComplete:?action??????????????
          ????????}
          );
          ????????
          ????????$('name1').readOnly?
          =?true
          ????????$('name1').style.background?
          =?'lightblue'
          ????????$('text1').innerText
          =''?
          ????}

          ?????? //局部刷新 并提取 語句
          ????
          function?Said(){
          ????????
          var?url?=?'http://192.168.1.130:7000/xxs/mySaid.do';??
          ????????new?Ajax.PeriodicalUpdater(
          ????????????'div1',
          ????????????url,
          ????????????
          {
          ????????????????method:?'get',
          ????????????????onComplete:?SumSaid,
          ????????????????evalScripts:?
          true,
          ????????????????frequency:?
          1,
          ????????????????decay:?
          1
          ????????????}

          ????????);
          ????}

          ?????? //展現(xiàn)
          ????
          function?SumSaid(req){
          ????????$('div1').innerHTML?
          =?req.responseText;
          ????}


          ????
          function?action(req){
          ????}

          ????
          </script>
          ????

          Action
          ?? private static int SIZE = 30 ;
          ???? private List list = new ArrayList();

          ????
          public?ActionForward?execute(
          ????????ActionMapping?mapping,
          ????????ActionForm?form,
          ????????HttpServletRequest?request,
          ????????HttpServletResponse?response)?
          {
          ????????String?take?
          =?request.getParameter("take")?;
          ????????String?name?
          =?request.getParameter("name")?;
          ????????response.addHeader(
          "Cache-Control","no-cache");?
          ????????
          ????????request.setAttribute(
          "said",DueiLie(name,take));

          ????????
          try?{
          ????????????request.setCharacterEncoding(
          "gb2312");
          ????????????response.setCharacterEncoding(
          "gb2312");
          ????????}
          ?catch?(Exception?e)?{
          ????????}


          ????????
          return?mapping.findForward("list");
          ????}

          ?????
          ??????? //語句的組織
          ????
          public?String?DueiLie(String?name,String?take){
          ????????
          ????????StringBuffer?strb??
          =?new?StringBuffer();
          ????????
          if(name==null||take==null);
          ????????
          else{
          ????????????strb.append(?name?).append(
          "?:?").append(take).append("</br>")?;
          ????????????
          if(list.size()==SIZE){
          ????????????????list.remove(list.get(
          0));
          ????????????????list.add(strb.toString()?);
          ????????????}
          else{
          ????????????????list.add(?strb.toString()?);
          ????????????}

          ????????}

          ????????StringBuffer?takes?
          =?new?StringBuffer();
          ????????Iterator?it?
          =?list.iterator();
          ????????
          while(it.hasNext()){
          ????????????takes.insert(?
          0,(String)it.next()?);
          ????????}

          ????????
          return?takes.toString();
          ????}

          jsp ( list ) 中文處理 jsp 就一句話
          <%= new String(((String)request.getAttribute("said")).getBytes("iso8859-1"),"GBK") %>

          posted on 2007-06-13 11:07 好學蜘蛛 閱讀(334) 評論(0)  編輯  收藏 所屬分類: JAVA 、struts 、AJAX WEB2.0

          主站蜘蛛池模板: 靖西县| 特克斯县| 抚松县| 叙永县| 玉门市| 玉林市| 绍兴县| 蒲城县| 冀州市| 阳城县| 秭归县| 青冈县| 涟水县| 吉安市| 庆元县| 长子县| 南岸区| 兴化市| 大埔区| 习水县| 夏津县| 萍乡市| 茂名市| 清徐县| 东乡县| 昭觉县| 交口县| 淅川县| 延安市| 准格尔旗| 卢氏县| 祥云县| 温泉县| 兴和县| 孝感市| 景洪市| 渝中区| 安龙县| 龙川县| 醴陵市| 石城县|