您好,登錄后才能下訂單哦!
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 響應(yīng)頭(服務(wù)-》客戶端)
public class Demo extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
////服務(wù)端通知客戶端重定向
response.setStatus(302);
//服務(wù)端通知客戶端重定向的目標(biāo)資源
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>
訪問(wèn)
輸入地址:
http://localhost:8080/day04/Demo
結(jié)果成如下
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。