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());是這個嗎