response.sendRedirect 和setHeader ()
没有程序渣的理想天国。
1,setHeader()⽅法
⽤setHeader()⽅法设置响应头,为刷新“refresh”,然后设置⼏秒后刷新的时间和url 地址
2,sendRedirect()⽅法请求重定向response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8");然后就会重新定向到相应的servlet
重定向到的页⾯/servlet/demo8
结果最后重定向的结果如下
blog.csdn/code_my_dream/article/details/68068211
1,setHeader()⽅法
⽤setHeader()⽅法设置响应头,为刷新“refresh”,然后设置⼏秒后刷新的时间和url 地址[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. 04. //设置返回客户端的编码 05. response.setContentType("text/html;charset=UTF-8"); 06. /*response.setIntHeader("refresh", 1);//设置1秒钟刷新⼀次 07. 08. Random r = new Random(); 09. 10. Writer().Int()+"");*/ 11. 12. Writer().write("注册成功!3秒钟跳到主页"); 13. //设置3秒钟跳转 14. response.setHeader("refresh", "3;url=/day09_00_HttpServletResponse/servlet/demo6"); 15. }
[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. System.out.println("A:我要借钱!"); 04. System.out.println("B:我不有,但是我可以告诉你谁有"); 05. /*//告诉客户端要重新定向新的资源 06. response.setStatus(302); 07. //告诉浏览器要去访问哪个URL 08. response.setHeader("location", "/day09_00_HttpServletResponse/servlet/demo8");*/ 09. 10. //请求重定向 11. response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8"); 12. 13. System.out.println("A: 我去了"); 14. 15. }
[java]
nextint()方法01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. System.out.println("我有钱,我借你!"); 04. }
[java]
2,sendRedirect()⽅法请求重定向response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8");然后就会重新定向到相应的servlet
重定向到的页⾯/servlet/demo8
结果最后重定向的结果如下
blog.csdn/code_my_dream/article/details/68068211
1,setHeader()⽅法
⽤setHeader()⽅法设置响应头,为刷新“refresh”,然后设置⼏秒后刷新的时间和url 地址01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. 04. //设置返回客户端的编码 05. response.setConte
ntType("text/html;charset=UTF-8"); 06. /*response.setIntHeader("refresh", 1);//设置1秒钟刷新⼀次 07. 08. Random r = new Random(); 09. 10. Writer().Int()+"");*/ 11. 12. Writer().write("注册成功!3秒钟跳到主页"); 13. //设置3秒钟跳转 14. response.setHeader("refresh", "3;url=/day09_00_HttpServletResponse/servlet/demo6"); 15. }
[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. System.out.println("A:我要借钱!"); 04. System.out.println("B:我不有,但是我可以告诉你谁有"); 05. /*//告诉客户端要重新定向新的资源 06. response.setStatus(302); 07. //告诉浏览器要去访问哪个URL 08. response.setHeader("location", "/day09_00_HttpServletResponse/servlet/demo8");*/ 09. 10. //请求重定向 11. response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8"); 12. 13. System.out.println("A: 我去了"); 14. 15. }
[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. thro
ws ServletException, IOException { 03. System.out.println("我有钱,我借你!"); 04. }
[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. 04. //设置返回客户端的编码 05. response.setContentType("text/html;charset=UTF-8"); 06. /*response.setIntHeader("refresh", 1);//设置1秒钟刷新⼀次 07. 08. Random r = new Random(); 09. 10. Writer().Int()+"");*/ 11. 12. Writer().write("注册成功!3秒钟跳到主页");
2,sendRedirect()⽅法请求重定向response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8");然后就会重新定向到相应的servlet
重定向到的页⾯/servlet/demo8
结果最后重定向的结果如下
1,setHeader()⽅法
⽤setHeader()⽅法设置响应头,为刷新“refresh”,然后设置⼏秒后刷新的时间和url 地址
2,sendRedirect()⽅法请求重定向response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8");然后就会重新定向到相应的servlet 13. //设置3秒钟跳转 14. response.setHeader("refresh", "3;url=/day09_00_HttpServletResponse/servlet/demo6"); 15. } [java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. System.out.println("A:我要借钱!"); 04. System.out.println("B:我不有,但是我可以告诉你谁有"); 05. /*//告诉客户端要重新定向新的资源 06. response.setStatus(302); 07. //告诉浏览器要去访问哪个URL 08. response.setHeader("location", "/day09_00_HttpServletResponse/servlet/demo8");*/ 09. 10. //请求重定向 11. response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8"); 12. 13. System.out.println("A: 我去了"); 14. 15. }
[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. System.out.println("我有钱,我借你!"); 04. } [ja
va]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. 04. //设置返回客户端的编码 05. response.setContentType("text/html;charset=UTF-8"); 06. /*response.setIntHeader("refresh", 1);//设置1秒钟刷新⼀次 07. 08. Random r = new Random(); 09. 10. Writer().Int()+"");*/ 11. 12. Writer().write("注册成功!3秒钟跳到主页"); 13. //设置3秒钟跳转 14. response.setHeader("refresh", "3;url=/day09_00_HttpServletResponse/servlet/demo6"); 15. }
[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. System.out.println("A:我要借钱!"); 04. System.out.println("B:我不有,但是我可以告诉你谁有"); 05. /*//告诉客户端要重新定向新的资源
重定向到的页⾯/servlet/demo8
结果最后重定向的结果如下
blog.csdn/code_my_dream/article/details/68068211
1,setHeader()⽅法
⽤setHeader()⽅法设置响应头,为刷新“refresh”,然后设置⼏秒后刷新的时间和url 地址
2,sendRedirect()⽅法请求重定向response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8");然后就会重新定向到相应的servlet 06. response.setStatus(302); 07. //告诉浏览器要去访问哪个URL 08. response.setHeader("location", "/day09_00_HttpServletResponse/servlet/demo8");*/ 09. 10. //请求重定向 11. response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8"); 12. 13. System.out.println("A: 我去了"); 14. 15. }
[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. System.out.println("我有钱,我借你!"); 04. } [java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. thro
ws ServletException, IOException { 03. 04. //设置返回客户端的编码 05. response.setContentType("text/html;charset=UTF-8"); 06. /*response.setIntHeader("refresh", 1);//设置1秒钟刷新⼀次 07. 08. Random r = new Random(); 09. 10. Writer().Int()+"");*/ 11. 12. Writer().write("注册成功!3秒钟跳到主页"); 13. //设置3秒钟跳转 14. response.setHeader("refresh", "3;url=/day09_00_HttpServletResponse/servlet/demo6"); 15. }
[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. System.out.println("A:我要借钱!"); 04. System.out.println("B:我不有,但是我可以告诉你谁有"); 05. /*//告诉客户端要重新定向新的资源 06. response.setStatus(302); 07. //告诉浏览器要去访问哪个URL 08. response.setHeader("location", "/day09_00_HttpServletResponse/servlet/demo8");*/ 09. 10. //请求重定向 11. response.sendRedirect("/day09_00_HttpServletResponse/servlet/demo8"); 12. 13. System.out.println("A: 我去了"); 14. 15. }
重定向到的页⾯/servlet/demo8
结果最后重定向的结果如下[java]
01. public void doGet(HttpServletRequest request, HttpServletResponse response) 02. throws ServletException, IOException { 03. System.out.println("我有钱,我借你!"); 04. }
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论