實現(xiàn)自動刷新和重定向
// 自動刷新
public class Demo1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader("content-type", "text/html;charset=utf-8");
response.getWriter().write("注冊成功鸣驱,3秒鐘后自動跳轉(zhuǎn)对蒲!");
response.setHeader("refresh", "3;url=http://www.baidu.com");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
// 重定向
public class Demo1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 方法1
response.setStatus(302);// 告訴客戶端,重定向
response.setHeader("location", "/JDemo/demo2");// 告訴客戶端,重定向的位置
// 方法2
response.sendRedirect("/JDemo/demo2");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者