Posted on 2007-06-13 10:22
G_G 閱讀(1450)
評論(3) 編輯 收藏 所屬分類:
javascript
問題 :
提供給B/S 結(jié)構(gòu)一個實時的運行展現(xiàn)
解決:?? prototype 的?Ajax.PeriodicalUpdater 更新
??????????? prototype 的??? Ajax.Request 語句提交
????????????action 語句的組織展現(xiàn)
http://www.tkk7.com/Files/Good-Game/take.rar????沒有l(wèi)ib 大家可以就加 struct 相關(guān) 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"??>
??????? //語句異步提交給服務(wù)器 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") %>
心得:別人做到了 我也能做到
?????????要學(xué)的東西很多 多看書 多留意 多保護好身體 