The web page auto-refresh function is already common on the web site, such as instant news and stock information. In the traditional web implementation mode, to achieve similar effects, you must refresh the entire page. When the network speed is limited, this... syntaxHighlighter. all ();
The web page auto-refresh function is already common on the web site, such as instant news and stock information. In the traditional web implementation mode, to achieve similar effects, you must refresh the entire page. When the network speed is limited, this method affects the processing of the entire page due to a local change. The emergence of Ajax solves this problem well. Ajax technology can be used to partially refresh webpages, only update specified data, and not update other data.
Create an instance to demonstrate the automatic refresh function of the webpage. This instance simulates Subtitles displayed in the train ticket hall.
1. server code
The server-side code function of this instance is simple, that is, a random number is generated and returned to the client in the form of an XML file. Open notepad and enter the following code:
<% @ Page contentType = "text/html; charset = gb2312" %>
<%
Response. setContentType ("text/xml; charset = UTF-8"); // set the format and Character Set of the output information
Response. setHeader ("Cache-Control", "no-cache ");
Out. println (" ");
For (int I = 0; I <2; I ++ ){
Out. println (" "+ (Int) (Math. random () * 10) +" ");
Out. println (" "+ (Int) (Math. random () * 100) +" ");
}
Out. println (" ");
Out. close ();
%>
Save the preceding code named auto. jsp. In this file, use the Math class in the java. lang package to generate a random number.
2. client code
The client code of this instance mainly uses the numbers returned by the server to specify the display style. Open notepad and enter the following code:
<% @ Page language = "java" import = "java. util. *" pageEncoding = "GBK" %>