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

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

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

    weidagang2046的專欄

    物格而后知致
    隨筆 - 8, 文章 - 409, 評(píng)論 - 101, 引用 - 0
    數(shù)據(jù)加載中……

    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 閱讀(526) 評(píng)論(0)  編輯  收藏 所屬分類: Java

    主站蜘蛛池模板: 一级毛片大全免费播放| 国产亚洲A∨片在线观看| 亚洲国产综合精品一区在线播放| 亚洲AV综合色区无码另类小说| 久草免费福利在线| 亚洲国产精品日韩专区AV| 在线观看亚洲精品专区| 国产亚洲人成在线播放| 日韩午夜免费视频| 亚洲狠狠色丁香婷婷综合| 国产高清免费的视频| 免费一级特黄特色大片| 免费网站观看WWW在线观看| 在线观看成人免费视频不卡| 亚洲国产综合人成综合网站| 日韩少妇内射免费播放| 亚洲自偷自偷图片| 久久久久国色av免费看| 亚洲精品视频免费看| 成年女人午夜毛片免费看| 精品一区二区三区无码免费直播| 亚洲日韩国产一区二区三区| 中文字幕无线码免费人妻| 久久丫精品国产亚洲av不卡| 97碰公开在线观看免费视频| 亚洲AV电影天堂男人的天堂| 亚洲精品成人区在线观看| 玖玖在线免费视频| 国产色在线|亚洲| 五月婷婷亚洲综合| 国产精品免费高清在线观看| 亚洲av午夜精品无码专区| 亚洲国产成人久久笫一页| 免费A级毛片无码A∨中文字幕下载| 亚洲一本之道高清乱码| 亚洲 小说区 图片区 都市| 另类免费视频一区二区在线观看 | 深夜国产福利99亚洲视频| 日本免费A级毛一片| 亚洲人成图片网站| 日本免费久久久久久久网站|