JavaWeb-Refresh响应头
Posted 爱编程DE文兄
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaWeb-Refresh响应头相关的知识,希望对你有一定的参考价值。
一.Refresh响应头:可以理解为定时的重定向,在指定的时间后发生页面的跳转
二.代码示例:
package cn.xxx.Servlet; 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 DServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print("xxxx"); //3秒之后跳转到/Demo01/EServlet response.setHeader("refresh", "3;URL=/Demo01/EServlet"); } }
package cn.xxx.Servlet; 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 EServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().print("XXX"); } }
以上是关于JavaWeb-Refresh响应头的主要内容,如果未能解决你的问题,请参考以下文章