使用request對象獲取用戶請求的URL路徑


假如一個請求為        http://localhost:8080/pro/test

request.getServerName()                    能得到其中的  localhost

request.getServerPort()                       能得到其中的  8080

request.getRequestURL()                    能得到其中的   /pro/test  (就是請求的項目名+請求路徑)

request.getServletContext().getContextPath()           能得到其中的  /pro    (也就是項目名)

request.getServletPath()                                            能得到其中的  /test      (請求路徑)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM