页面定时跳转(读秒)
生活随笔
收集整理的這篇文章主要介紹了
页面定时跳转(读秒)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
頁面定時刷新(頁面讀秒操作)* 響應的頭 refresh <meta http-equiv="refresh" content="5;url=/day10/response/login.html">
發送http頭,控制瀏覽器定時刷新網頁(refresh)
多學一招:HTML<meta>標簽來控制瀏覽器行為
package cn.learn.response;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** 頁面的定時跳轉* @author Administrator**/
public class RefreshServlet extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {// 讀秒操作response.setContentType("text/html;charset=UTF-8");response.getWriter().write("<h1>頁面將在5秒后跳轉</h1>");// 通過refresh頭完成頁面刷新response.setHeader("refresh", "5;url=/day10/response/login.html");}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {doGet(request, response);}}
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 5秒后跳轉 -->
<meta http-equiv="refresh" content="5;url=/day10/response/login.html">
<title>頁面定時跳轉(讀秒)</title>
</head>
<body onload="run()"><h2>頁面將在<span id="spanId">5</span>秒后跳轉</h2></body><script type="text/javascript">/* 讀秒的操作頁面一加載,加載事件 onload執行讀秒的操作,每隔一秒變一次。每隔一秒,js的定時器*/var x = 5;function run(){var span = document.getElementById("spanId");span.innerHTML = x;x--;window.setTimeout("run()", 1000);}</script></html>
?
總結
以上是生活随笔為你收集整理的页面定时跳转(读秒)的全部內容,希望文章能夠幫你解決所遇到的問題。