<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    weidagang2046的專欄

    物格而后知致
    隨筆 - 8, 文章 - 409, 評論 - 101, 引用 - 0
    數據加載中……

    What's the difference between "redirect" & "forward" in servelt?

    Suppose you have a servlet that just does another redirect to another URL:

    protectedvoid doGet(HttpServletRequest request, HttpServletResponse response)
    {
      response.sendRedirect("/anotherURL");
    }


    This servlet is accessible through the URL /redirectServlet.

    When the client browser makes a request for /redirectServlet, it receives a response (an HTTP 302 response) that tells it that the document it requested can actually be found at /anotherURL. The client uses the URL it gets and makes a new request to /anotherURL.

    The redirect URL doesn't have to be on the same server as the original URL. If the redirect URL (/anotherURL) points to another servlet, new request and response objects will be created to handle the new request.

    Suppose our redirect servlet is now changed to do a forward instead of a redirect:

    protectedvoid doGet(HttpServletRequest request, HttpServletResponse response)
    {
      ServletContext context = getServletContext();
      RequestDispatcher dispatcher = context.getRequestDispatcher("/anotherURL");
      dispatcher.forward(request, response);
    }


    This modified servlet is accessible through the URL /forwardServlet.

    When the client makes a request to our forwarding servlet this time, it no longer receives the redirect response. The dispatcher.forward line causes the servlet container to run the servlet associated with the url /anotherURL directly. The client will receive the result of /anotherURL, even though they requested /forwardServlet.

    A few more notes:

    * Redirect is a two step process. The web server tells the browser to request a second URL.
    * If the user reloads, the second URL will be reloaded (/anotherURL instead of /redirectServlet).
    * Redirect is always slower than a forward because it requires a second client request.
    * Attributes placed in the request scope of the redirecting servlet are not available in the request scope of the second rrequest.

    * Forwards are performed internally to the web server.
    * The browser is completely unaware that the forward took place - the original URL (/forwardServlet) remains in the address bar.
    * If the user does a reload, the browser will repeat the original request with the original URL (/forwardServlet).

    from: http://forum.java.sun.com/thread.jspa?threadID=627801&messageID=3597659

    posted on 2006-11-03 02:19 weidagang2046 閱讀(519) 評論(0)  編輯  收藏 所屬分類: Java

    主站蜘蛛池模板: 亚洲aⅴ无码专区在线观看| 亚洲视频在线观看免费视频| 亚洲午夜在线播放| 国产午夜影视大全免费观看| 亚洲乱码中文字幕小综合| 91免费人成网站在线观看18| 亚洲视频免费观看| 国产精彩免费视频| 亚洲国产av一区二区三区| 特级毛片A级毛片100免费播放| 国产三级电影免费观看| 夜夜爽妓女8888视频免费观看| 亚洲一区日韩高清中文字幕亚洲| 亚洲依依成人亚洲社区| 曰皮全部过程视频免费国产30分钟| 午夜亚洲WWW湿好爽| 亚洲精品无码成人片在线观看| 最新亚洲成av人免费看| 午夜男人一级毛片免费| 又硬又粗又长又爽免费看| 国产亚洲综合成人91精品| 国产高清不卡免费在线| 国产成人va亚洲电影| 亚洲线精品一区二区三区影音先锋 | 伊人久久大香线蕉亚洲五月天| 在线观看黄片免费入口不卡| 亚洲色图在线观看| 麻豆成人精品国产免费| jizz在线免费播放| 亚洲春黄在线观看| 欧洲人成在线免费| 亚洲国产精品无码专区| 免费看黄视频网站| 一级午夜免费视频| 久久久久国产亚洲AV麻豆| 一区二区三区四区免费视频| 伊人久久亚洲综合影院首页| 久久久久亚洲爆乳少妇无| 四虎在线最新永久免费| 黄色a三级三级三级免费看| 91精品国产亚洲爽啪在线影院|