關於轉發與重定向路徑的問題

在學習javaweb時,我們可能經常會被這個問題難倒:相同的路徑,轉發後出現 404 錯誤,而重定向則不會。


   對於這個問題,我進行了多次反覆的測試,總結出了一下知識點:

   路徑有相對路徑和絕對路徑———當前路徑爲 http://localhost:8080/Test/Main :


   相對路徑:response.sendRedirect("index.jsp")------htttp://localhost:8080/Test/Main/index.jsp

       request.getRequestDispatcher("index.jsp")------htttp://localhost:8080/Test/Main/index.jsp


       絕對路徑:response.sendRedirect("/index.jsp")------htttp://localhost:8080/index.jsp

request.getRequestDispatcher("/index.jsp")------htttp://localhost:8080/Test/index.jsp       


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章