The home page (the page to be refreshed) requires that the system time be refreshed every minute
<HTML>
<Body onload = "makerequest (" getsystemtime. jsp ")"> // create an httprequest object
<Form name = "dateform">
<Table>
<TD colspan = "2" align = "center">
<Div id = "systimeshow"> </div> // display the platform system time
</TD>
</Table> </form>
</Body>
</Html>
Getsystemtime. jsp // obtain the current system time, that is, the page of the output result
<% @ Page Language = "Java" %>
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Page import = "Java. util. Date" %>
<% @ Page import = "Java. SQL. timestamp" %>
<% @ Page import = "Java. Io. ioexception" %>
<%
Date d = new date ();
Timestamp Ts = new timestamp (D. gettime ());
String result = ts. tostring (). substring (0, 16 );
Out. Write (result, 0, result. Length ());
%>
Ajax. js
function makerequest (URL) {
http_request = false;
If (window. XMLHttpRequest) {
http_request = new XMLHttpRequest ();
If (http_request.overridemimetype) {
http_request.overridemimetype ('text/xml ');
}< BR >}else if (window. activexobject) {
try {
http_request = new activexobject ("msxml2.xmlhttp");
}catch (E) {
try {
http_request = new activexobject ("micro Soft. XMLHTTP ");
}catch (e) {
}< BR >}< br> If (! Http_request) {
alert ("your browser does not support the current operation. Please use IE 5.0 or later! ");
return false;
}< br>
// Define the page call method init, not Init (); No ();
Http_request.onreadystatechange = Init;
Http_request.open ('get', URL, true );
// Disable IE Cache
Http_request.setrequestheader ("If-modified-since", "0 ");
// Send data
Http_request.send (null );
// Refresh the page every 60 seconds
SetTimeout ("makerequest (" + URL + "')", 60000 );
}
function Init () {
If (http_request.readystate = 4) {
If (http_request.status = 0 | http_request.status = 200) {
var result = http_request.responsetext;
If (result = "") {
result = "failed to get system time ";
}< br> document. getelementbyid ("effecimeshow "). innerhtml = "platform system time:" + result;
}else {// http_request.status! = 200
alert ("request failed! ");
}< BR >}