getRequestUI and getRequestURL

getRequestUI()

api

 public String getRequestURI();

    /**
     *
     * Reconstructs the URL the client used to make the request.
     * The returned URL contains a protocol, server name, port
     * number, and server path, but it does not include query
     * string parameters.
<!--重新構造的url用於發出請求,那麼這個url則包含server name,port,path但不是不包含查詢字符串參數 -->
     *
     * <p>If this request has been forwarded using
     * {@link javax.servlet.RequestDispatcher#forward}, the server path in the
     * reconstructed URL must reflect the path used to obtain the
     * RequestDispatcher, and not the server path specified by the client.
     *
     <!-- **如果這個url被用來轉發,那麼這個重構的url地址是用RequestDispatcher來映射的,但是它並不是客戶端指定的訪問地址**-->
     * <p>Because this method returns a <code>StringBuffer</code>,
     * not a string, you can modify the URL easily, for example,
     * to append query parameters.
     *
     * <p>This method is useful for creating redirect messages
     * and for reporting errors.
     *
     <!-- 這個方法對於重定向非常有用-->
     * @return      a <code>StringBuffer</code> object containing
     *          the reconstructed URL
     *
     */
    <!-- 他返回一個重構的url-->

getRequestURL

public StringBuffer getRequestURL();


    /**
     *
     * Returns the part of this request's URL that calls
     * the servlet. This path starts with a "/" character
     * and includes either the servlet name or a path to
     * the servlet, but does not include any extra path
     * information or a query string. Same as the value of
     * the CGI variable SCRIPT_NAME.
<!-- 他返回一個請求URL,是以 / 開頭,包括server名字和path-但是不包括額外的路徑或者信息,->     

     * <p>This method will return an empty string ("") if the
     * servlet used to process this request was matched using
     * the "/*" pattern.
<!-- 此方法返回一個空字符串,servlet 會以/* 的樣式來處理-->
     *
     * @return      a <code>String</code> containing
     *          the name or path of the servlet being
     *          called, as specified in the request URL,
     *          decoded, or an empty string if the servlet
     *          used to process the request is matched
     *          using the "/*" pattern.
     *
     */
<!--這個請求URL將被servlet指定,解碼,或者一個空字符串如果servlet匹配成功,就用 /* 的模式 -->

Console

System.out.println("URI:  " +request.getRequestURI());
            System.out.println("URL:   "+ request.getRequestURL().toString());

URI:  /order/order.html
URL:   http://localhost:8092/order.html
發佈了76 篇原創文章 · 獲贊 19 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章