|
1,在前端页面内置一隐藏的内帧.内帧放置接收数据的刷新页面 2,用DHTML语法,定时将内帧中的数据或网页整个拷贝到前端页面中.这样,前端便可以做到不"刷新"且自动更新数据了.
附简单实现的代码. 前端:
A.HTM
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>8000MCU</title> </head> <script language="javascript"> function cccs() { setInterval(" iframe_fu.location = 'indextop1.jsp';",10000) //每十秒从后台页面INDEXTOP1.JSP中读取一次数据 } </script> <body onload="cccs()"> <div id="div"> 读取到的数据,替换掉DIV中的数据 </div>
<iframe id='iframe_fu' width='0' height='0' style='visibility:hidden'> </iframe>
</body> </html>
后台 indextop1.jsp <%@ page contentType="text/html;charset=gb2312" import="java.sql.*" %>
<% response.setHeader("Cache-Control","no-cache"); response.setHeader("Expires","0"); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>8000MCU</title> <link href="/blog/"";Css.css" rel="stylesheet" type="text/css"> <style type="text/css"> <!-- body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } --> </style> <link href="/blog/"";Css.css" rel="stylesheet" type="text/css"> </head>
<body> <div id="divs"> 呵呵,这就是每过十秒更新的动态页面数据. </div>
<script language="javascript"> var t=document.getElementById('divs'); var yy=parent.document.getElementById('div'); yy.innerHTML=t.innerHTML; </script> </body> </html>
|