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>
访问
输入地址:
http://localhost:8080/day04/Demo
结果成如下
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。