<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

    主站蜘蛛池模板: 四虎成人免费大片在线| 无码国产精品一区二区免费3p| 999久久久免费精品国产| 亚洲第一成年男人的天堂| 9久热精品免费观看视频| 中文字幕不卡亚洲| aa级毛片毛片免费观看久| 亚洲精品成人片在线观看精品字幕| 国产免费内射又粗又爽密桃视频| 亚洲区不卡顿区在线观看| 国产精品成人啪精品视频免费| 国产亚洲精品福利在线无卡一| 中文在线观看国语高清免费| 亚洲精品无码不卡在线播HE| 国产精成人品日日拍夜夜免费| 91亚洲自偷在线观看国产馆| 24小时免费直播在线观看| 亚洲s码欧洲m码吹潮| 亚洲成a人片在线观看久| 国产在线观看无码免费视频| 亚洲日本在线观看| 国产高清免费视频| 丰满亚洲大尺度无码无码专线 | fc2免费人成为视频| 亚洲精品卡2卡3卡4卡5卡区| 色欲色香天天天综合网站免费| 亚洲激情电影在线| 国产免费看插插插视频| 一级毛片免费全部播放| 亚洲人成网址在线观看| 精品久久久久久久免费人妻| 国产免费区在线观看十分钟| 久久亚洲AV成人无码| 24小时在线免费视频| 亚洲狠狠成人综合网| 亚洲国产小视频精品久久久三级| 久久久精品午夜免费不卡| 国产99在线|亚洲| 中文字幕亚洲专区| 在线看片免费不卡人成视频| 9久热这里只有精品免费|