posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          頁(yè)面嵌入在線聊天 (prototype)

          Posted on 2007-06-13 10:22 G_G 閱讀(1459) 評(píng)論(3)  編輯  收藏 所屬分類: javascript
          問(wèn)題 : 提供給B/S 結(jié)構(gòu)一個(gè)實(shí)時(shí)的運(yùn)行展現(xiàn)
          解決:?? prototype 的?Ajax.PeriodicalUpdater 更新
          ??????????? prototype 的??? Ajax.Request 語(yǔ)句提交
          ????????????action 語(yǔ)句的組織展現(xiàn)

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

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

          說(shuō)明:?
          ??????

          <!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="請(qǐng)輸入名字"?onfocus="if($('name1').value=='請(qǐng)輸入名字')?$('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"??>
          ??????? //語(yǔ)句異步提交給服務(wù)器 Ajax.Request
          ????
          function?onb(){?????????????????????????????????????????
          ??????
          if($('name1').value=='請(qǐng)輸入名字'?||?$('name1').value==''){
          ??????????window.alert('請(qǐng)輸入名字');
          ??????????
          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
          =''?
          ????}

          ?????? //局部刷新 并提取 語(yǔ)句
          ????
          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");
          ????}

          ?????
          ??????? //語(yǔ)句的組織
          ????
          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") %>

          心得:別人做到了 我也能做到
          ?????????要學(xué)的東西很多 多看書 多留意 多保護(hù)好身體

          評(píng)論

          # re: 頁(yè)面嵌入在線聊天 (prototype)[未登錄](méi)  回復(fù)  更多評(píng)論   

          2007-06-13 13:30 by 劉明
          可以給個(gè)Demo演示嗎?本人對(duì)struct不太懂。

          # re: 頁(yè)面嵌入在線聊天 (prototype)  回復(fù)  更多評(píng)論   

          2007-06-13 14:57 by G_G
          @劉明
          上頭下載的 就是 不過(guò)沒(méi) lib :( 有點(diǎn)大
          你可以看 .classpath 放lib 我的 .classpath 有點(diǎn)亂
          你加 struct 的 lib 就可以了
          { 有 動(dòng)態(tài)建表(2) bean[] 直接到建表 (擴(kuò)展也很好) 的文檔的 lib 在里面 }
          對(duì)不起大家了
          有問(wèn)題 到我
          liukaiyi@gmail.com 留言 謝謝

          # re: 頁(yè)面嵌入在線聊天 (prototype)  回復(fù)  更多評(píng)論   

          2007-06-13 17:16 by IT進(jìn)行時(shí)
          還是用smack吧,簡(jiǎn)單又“正統(tǒng)”。
          主站蜘蛛池模板: 汉川市| 峨眉山市| 靖江市| 蓝田县| 开鲁县| 阳西县| 通山县| 乡城县| 泊头市| 健康| 满洲里市| 盐亭县| 玉溪市| 定边县| 大姚县| 灵武市| 长春市| 光山县| 益阳市| 拉萨市| 蕉岭县| 涡阳县| 应城市| 苏尼特右旗| 法库县| 泰来县| 佛坪县| 泰州市| 子长县| 庆云县| 莎车县| 雷波县| 呼伦贝尔市| 兴海县| 灵璧县| 祁阳县| 环江| 湖州市| 九江县| 内乡县| 卓尼县|