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

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

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

    posts - 14,  comments - 37,  trackbacks - 0

    Javax.servlet.RequestDispatcher.forward(ServletRequest request, ServletResponse response)

    Javax.servlet.http.HttpServletResponse.sendRedirect(String location)

    forward

    作用于服務(wù)器端,重定向后客戶端瀏覽器地址欄的URL不變,無法通過get方式傳遞參數(shù),不過可以通過HttpServletResponse. setAttribute(key, values)來做:

    JDK的DOC中的描述:

    Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. This method allows one servlet to do preliminary processing of a request and another resource to generate the response.

    forward should be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws an IllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward.

    這個(gè)方法允許一個(gè)servlet對一個(gè)請求作完處理后,并使用另一個(gè)資源作響應(yīng)。

    forward應(yīng)該在向客戶端發(fā)出響應(yīng)之前被調(diào)用(response的輸出流被刷新之前),如果已經(jīng)向客戶端發(fā)出了響應(yīng),這個(gè)方法將拋出一個(gè) “IllegalStateException”的異常。未發(fā)出響應(yīng)response的輸出緩沖區(qū)在調(diào)用forward會(huì)被自動(dòng)的清空。

    得到RequestDispatcher引用的方法:

    1、 javax.servlet.ServletContext.getRequestDispatcher(String path)

    JDK的DOC中的描述:

    The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.

    用的最多,最容易理解的方法,path必須是以“/”開頭,路徑是相對于全局上下文路徑,對應(yīng)于web應(yīng)用的根目錄

    2、javax.servlet.ServletRequest.getRequestDispatcher(String path)

    JDK的DOC中的描述:

    The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root. This method returns null if the servlet container cannot return a RequestDispatcher.

    可以是相對地址,以當(dāng)前資源的根目錄,但不能超出當(dāng)前資源根目錄。

    可以是以“/”開頭的地址,當(dāng)前root作為根目錄環(huán)境。

    2、 javax.servlet.ServletContext.getNamedDispatcher(String name)

    JDK的DOC中的描述:

    Servlets (and JSP pages also) may be given names via server administration or via a web application deployment descriptor.

    得到名為name的資源。

    Servlets(也可是JSP 頁面)可能會(huì)有個(gè)給定的名字,該名字是服務(wù)器或者web應(yīng)用的部署描述web.xml提供的。

    sendRedirect

    工作在客戶端,重定向后客戶端瀏覽器地址欄的URL變?yōu)樾碌馁Y源URL,可以通過get方式傳遞參數(shù)。

    JDK的DOC的描述:

    Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.

    If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

    這個(gè)方法可以接受相對的URL,在發(fā)送響應(yīng)之前servlet容器會(huì)將其轉(zhuǎn)化為絕對的URL。如果相對的URL不以“/”開頭,容器將解釋為是相對當(dāng)前請求的路徑URI,如果是以“/”開頭,則解釋為是相對于servlet容器的更目錄環(huán)境。

    注意:如果已經(jīng)向客戶端響應(yīng)了請求,這個(gè)方法將拋出一個(gè)“IllegalStateException”的異常。調(diào)用了這個(gè)方法后,這個(gè)響應(yīng)是否被提交或是否提交完畢。

    sendRedirect比較簡單,參數(shù)location就是代表重定向目標(biāo)新資源

    localtion可以有以下幾種情況:

    可以是絕對地址,如:http://localhost:8080/servlet/a.jsp

    可以是相對地址,相對于當(dāng)前訪問資源的根目錄,如:a.jsp

    可以是以“/”開頭的地址,則認(rèn)為是先對該web應(yīng)用的根目錄,如:/a.jsp

    posted on 2007-07-10 09:50 冰封的愛 閱讀(143) 評論(0)  編輯  收藏 所屬分類: J2EE
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(3)

    隨筆檔案

    文章分類

    文章檔案

    相冊

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国产成人无码区免费A∨视频网站| 日本免费大黄在线观看| 无人在线观看免费高清视频| 亚洲视频一区在线观看| 久久久久久影院久久久久免费精品国产小说 | 亚洲永久网址在线观看| 色窝窝免费一区二区三区| 国产 亚洲 中文在线 字幕 | 99视频全部免费精品全部四虎 | 亚洲国产中文v高清在线观看| 美女黄频免费网站| 亚洲性久久久影院| 亚洲免费观看视频| 亚洲视频在线观看视频| AV大片在线无码永久免费| 亚洲国产日韩精品| 免费在线观看理论片| a级毛片毛片免费观看永久| 亚洲电影国产一区| 性短视频在线观看免费不卡流畅| 亚洲欧洲无卡二区视頻| 全亚洲最新黄色特级网站 | 亚洲综合色区在线观看| 国产午夜精品久久久久免费视 | 午夜在线亚洲男人午在线| 国产亚洲精品激情都市| 99热免费在线观看| 亚洲精华国产精华精华液好用| 伊人久久亚洲综合影院| 在线观看免费无码视频| 亚洲av永久无码精品三区在线4| 在线精品免费视频| 丝瓜app免费下载网址进入ios| 亚洲色成人网一二三区| 四虎影视精品永久免费| 免费国产成人α片| 精品国产亚洲AV麻豆| 亚洲AV日韩AV天堂久久| 国产国产人免费人成免费视频 | 日韩精品无码免费专区网站| 亚洲国产av一区二区三区丶|