test.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DWR測試</title>
<script type="text/javascript" src='<%= request.getContextPath() %>/dwr/interface/bu.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/engine.js'></script>
<script type='text/javascript' src='<%= request.getContextPath() %>/dwr/util.js'></script>
</head>
<script>
var i=0;
function init()
{
window.setInterval('Check()',5000);
//每隔5秒自動調用Check()
}
function Check()
{
var trobj=document.getElementById("1");
trobj.cells(1).innerText="風調雨順"+i;
i++;
}
</script>
<body οnlοad="init()">
本程序,在指定表格內使用AJAX,每5秒無閃動更新表格中“風調雨順”
<form action="" name="post">
<table id="news" cellspacing="2" cellpadding="2" align="center" border="2" bgcolor="#c0c0c0">
<tr>
<td width="15%">名稱</td><td width="55%">內容</td>
</tr>
<tr id="1">
<td>國內</td><td>風調雨順</td><td></td>
</tr>
<tr id="2">
<td>國外</td><td>地震不斷</td><td></td>
</tr>
<tr id="3">
<td>世界</td><td>風景這邊最好</td><td></td>
</tr>
</table>
</form>
</body>
</html>