如何用setHeader("refresh"...實現(xiàn)跳轉(zhuǎn)?
用setHeader("refresh"...跳轉(zhuǎn):
馬克- to-win:馬克 java社區(qū):防盜版實名手機(jī)尾號: 73203。
馬克-to-win:使用response對象的setHeader()方法可以實現(xiàn)在某個時間點(diǎn)跳轉(zhuǎn)到某個頁面的作用。比如 response.setHeader("refresh",60);可以實現(xiàn)六十秒以后,又一次訪問當(dāng)前頁面。而response.setHeader ("refresh","3;URL=http://localhost:8080/ServletHello/cookie.html"); 實現(xiàn)3秒后訪問新頁面:http://localhost:8080/ServletHello/cookie.html。
例:3.2.1
package com;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DeleteCookie extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setHeader("refresh","2;URL=http://localhost:8080/ServletHello/cookie.html");
}
}