重定向 302 与localhost 学习笔记
生活随笔
收集整理的這篇文章主要介紹了
重定向 302 与localhost 学习笔记
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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>訪問
輸入地址:
http://localhost:8080/day04/Demo
結果成如下
轉載于:https://blog.51cto.com/357712148/2104327
總結
以上是生活随笔為你收集整理的重定向 302 与localhost 学习笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DatePickerDialog日期对话
- 下一篇: 简单工厂模式(Simple Factor