java中通過request擷取路徑中的不同資訊,javarequest

來源:互聯網
上載者:User

java中通過request擷取路徑中的不同資訊,javarequest

aa為工程中的項目名

bb為webRoot下的檔案夾

1、request.getContextPath(); 輸出結果:/aa

2、request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path; 輸出結果:http://localhost:8080/aa

3、request.getServletPath();(擷取用戶端請求檔案的路徑)輸出結果:/bb/content/contentList.jsp

4、request.getRequestURI();(擷取發出請求字串的用戶端地址,得到的是requestURL的部分值,並且web容器沒有decode過的)輸出結果:/aa/bb/content/contentList.jsp

5、request.getRequestURL();(返回請求全部,包括http協議,servlet名字,連接埠號碼,映射路徑,但不包含請求參數,)輸出結果:http://localhost:8080/aa/bb/content/contentList.jsp



java 中如果擷取來訪路徑?

Javascript 中
1.獲得上一個頁面的URL地址
var url = document.referrer;
2.獲得當前頁面的URL地址
var ur = location.href ;
java 中
1.獲得上一個頁面的URL地址
Request.getHeader("Referer");
2 獲得當次請求的URI請求相對路徑和請求參數
request.getRequestURI()+"?"+request.getQueryString();
 
java怎擷取request的傳入的上一個頁面路徑

System.out.println("Request URI: " + request.getRequestURI());是這個嗎
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.