温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

重定向 302 与localhost 学习笔记

发布时间:2020-06-18 20:02:13 来源:网络 阅读:742 作者:知止内明 栏目:web开发

1、新建工程:

import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; //重定向 302 与localhost 响应头(服务-》客户端) public class Demo extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ////服务端通知客户端重定向 response.setStatus(302); //服务端通知客户端重定向的目标资源 response.setHeader("location", "WEB-INF/my.html"); } }

新建 my.html

<!DOCTYPE html> <html> <head> <title>my.html</title> <meta name="keywords" content="keyword1,keyword2,keyword3"> <meta name="description" content="this is my page"> <meta name="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> localhost+302 </body> </html> 

访问

重定向 302 与localhost 学习笔记

输入地址:
http://localhost:8080/day04/Demo
结果成如下

重定向 302 与localhost 学习笔记

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI