使用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