Posted on 2007-06-13 10:22
G_G 阅读(1444)
评论(3) 编辑 收藏 所属分类:
javascript
问题 :
提供给B/S 结构一个实时的运行展现
解决: prototype 的 Ajax.PeriodicalUpdater 更新
prototype 的 Ajax.Request 语句提交
action 语句的组织展现
http://www.blogjava.net/Files/Good-Game/take.rar 没有lib 大家可以就加 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
}
);
}
//展现
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") %>
心得:别人做到了 我也能做到
要学的东西很多 多看书 多留意 多保护好身体