JSP simple exercise-timed refresh page and jsp exercise refresh page

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.