JSP simple exercise-timed refresh page and jsp exercise refresh page
<% @ Page contentType = "text/html; charset = gb2312" %> <% @ page import = "java. util. date "%>
The date method is used in the program. You can use the import command at the beginning of the page to import java. util. date class; the program uses the setHeader () method of the response object to set the value of refresh information in the HTTP header, so that the webpage is continuously refreshed to get the latest time, and the page is refreshed every second.
<% @ Page contentType = "text/html; charset = gb2312" %> <% @ page import = "java. util. date, java. text. simpleDateFormat "%>
The SimpleDateFormat class is used to format the display format of the date data. The constructor parameter of the SimpleDateFormat class is a formatted string, that is, "MM minutes ss seconds at hh on mm dd, yyyy".
Jsp automatic page refresh
Jquery has a timer plug-in jquery1.6 version called jquery. timers-1.2.js
The call method is to introduce jquery into timer js.
Start with calling the following code
1000 represents the number of seconds in your text box, but it is in milliseconds. Label is a string that is the alias of your timer. function writes the code you refreshed, refreshes with ajax, or uses window. location. href.
$ ("Body"). everyTime (1000, label, function (){});
End your timer
$ ("Body"). stopTime ();
On the JSP page, I asked the programs that automatically refresh the page and regularly jump to the page. Generally, JSP or JavaScript is recommended?
Of course, js
Time can be generated in the background
<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<Meta name = "Generator" CONTENT = "EditPlus">
<Meta name = "Author" CONTENT = "">
<Meta name = "Keywords" CONTENT = "">
<Meta name = "Description" CONTENT = "">
</HEAD>
<Script language = "JavaScript">
<! --
Var time = 8; // time, in seconds
Function Redirect (){
Window. location = "www.baidu.com ";
}
Var I = 0;
Function dis (){
Document. all. s. innerHTML = "remaining" + (time-I) + "seconds ";
I ++;
}
Timer = setInterval ('dis () ', 1000); // display time
Timer = setTimeout ('redirect () ', time * 1000); // jump
// -->
</SCRIPT>
<BODY>
<Span id = "s"> </span>
</BODY>
</HTML>