A refresh header field is defined in the HTTP protocol to automatically refresh the page after telling the browser. After the time setting value of the Refresh header field, you can also use the semicolon (;), then specify a URL address, which will automatically access the URL address after the specified time value will automatically access the URL address.
: Hand experience: the effect of refresh header field
(1) Write a servlet that sets the Refresh header field according to the routine 5-2.
Routines 5-2 RefreshServlet.java
Import java.io. *;
Import javax.servlet. *;
Import javax.servlet.http. *;
Public Class RefreshServlet Extends Httpservlet
{
Public void service (httpservletRequest Request,
HttpservletResponse response) THROWS servletexception, ioException
{
// Review one of the following two statements, view their respective running effects
Response.setHeader ("Refresh", "2");
//Response.setheader ("refresh "," 22;url=http://www.it315.org ");
Response.Getwriter (). Println (New java.util.date ());
}
}
Compile the RefreshServlet.java source file using Compile.bat to ensure that the Class file generated after compile is stored in the
(2) Modify the
servlet>
......
......
servlet-maping>
After saving the Web.xml file, restart Tomcat.
(3) Enter the following address in the browser address bar:
http: // localhost: 8080 / it315 / servlet / refreshServlet
You can see the effect of automatically refresh the web document after the browser two seconds.
(4) Comment out the statement of the first section of the RefreshServlet.java source file comment out, and cancels the comments of the second sentence of the SETHEADER method. After recompilating the refreshServlet.java source file and waits Tomcat to reload the RefreshServlet, repeat step (3) operation, you can see the running effect of http://www.it315.org after two seconds.