jsp之 ---- 頁面重新導向和請求轉寄(筆記之深度說明)

來源:互聯網
上載者:User

標籤:style   blog   http   io   ar   color   os   sp   for   

 

          1.    HttpServletResponse對象的sendRedirect(String location)方法稱作重新導向。 如果location地址前面加上“/”,則表示

 相對於Servlet容器的根來請求。 即 http://localhost:8080,如果location 地址前米有加上‘/‘,則表示相對於當前請求的URL來尋找地址、 

                            response.sendRedirect("my.jsp");

  (無法擷取前面頁面的值,即便運用req.setAttribute("name",name) );

 

 

      2.  RequestDispatch的forward (request , response)稱作請求轉寄。

                 RequestDispatch rd = req.getRequestDispatcher("my.jsp");

                                            rd.forward(  request ,  response  );

      (即便不用req.setAttribute(“name”,name),運用request.getParameter()也可以擷取上一個頁面的值,但是如果用req.getAttribute()的話,必須運用req.setAttribute(“name”,name)否者無法擷取上一頁的值)

                             ----------------------這兩種在結果上,表面結果是一樣的。

     3.請求轉寄與重新導向的區別:

    1). 請求轉寄,整個過程處於同一個請求當中

 

  2). 重新導向  (實際上有兩個請求)

     

3)  . RequestDispathcher 是通過調用HttpservletRequset對象的getRequestDispatcher()方法得到的 , 是屬於請求對象的方法。。

 

4) . sendRedirect()是HttpServletResponse對象的方法,那就表明整個請求過程已經結束了 , 伺服器開始向用戶端返回執行的結果。

 

jsp之 ---- 頁面重新導向和請求轉寄(筆記之深度說明)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.