Difference requestDispatcher.forward and response.sendRedirect.

          Posted on 2006-03-02 20:54 killvin 閱讀(711) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): java
          引言
          在使用response的過(guò)程中經(jīng)常會(huì)遇到跳轉(zhuǎn)頁(yè)面的事情,這個(gè)時(shí)候有兩種情況供你選擇
          1。就是調(diào)用
          ServletContext.getRequestDispatcher(java.lang.String).forward(request ,
          response) ;
          2。就是調(diào)用response.setRedirect(),可是這兩個(gè)方法有什么不同呢?


          看看TSS上關(guān)于這個(gè)問(wèn)題的解釋?zhuān)?BR>Difference request.forward() and response.sendRedirect .
          Posted by: Kapil Israni on August 24, 2000 in response to Message #2253 1
          replies in this thread
          i suppose u r talking bout requestDispatcher.forward() here.

          well basically both method calls redirect u to new resource/page/servlet.

          the difference between the two is that sendRedirect always sends a header
          back to the client/browser. this header then contains the
          resource(page/servlet) which u wanted to be redirected. the browser uses
          this header to make another fresh request. thus sendRedirect has a overhead
          as to the extra remort trip being incurred. its like any other Http request
          being generated by ur browser. the advantage is that u can point to any
          resource(whether on the same domain or some other domain). for eg if
          sendRedirect was called at www.mydomain.com then it can also be used to
          redirect a call to a resource on www.theserverside.com.

          where as in case of forward() call, the above is not true. resources from
          the server, where the fwd. call was made, can only be requested for. but
          the major diff between the two is that forward just routes the request to
          the new resources which u specify in ur forward call. that means this route
          is made by the servlet engine at the server level only. no headers r sent
          to the browser which makes this very eficient. also the request and
          response objects remain the same both from where the forward call was made
          and the resource which was called.

          i hope i have hit ur question right.
          主站蜘蛛池模板: 衡南县| 德化县| 大安市| 根河市| 双峰县| 南郑县| 北京市| 永吉县| 车险| 丁青县| 台前县| 涞源县| 兴仁县| 无锡市| 新巴尔虎左旗| 高邮市| 饶河县| 云南省| 扎赉特旗| 绥江县| 进贤县| 许昌市| 桃园县| 西乌珠穆沁旗| 昌平区| 宁陵县| 五华县| 尼勒克县| 义马市| 宜城市| 会东县| 来宾市| 富平县| 巫山县| 巴楚县| 道孚县| 双桥区| 太和县| 平陆县| 广宗县| 浦北县|