获取当前页面关于地址的各项信息

请求地址为:http://localhost:8080/Logistics/index.jsp

1.request.getScheme()

返回当前链接使用的协议名称,默认是http

结果:http

2.request.getServerName()

返回当前网站的域名(本地为:localhost)

结果:localhost

3.request.getServerPort()

返回服务端口号

结果:8080

4.request.getContextPath()

返回应用的web目录的名称

结果:/Logistics

5.request.getServletPath()

返回当前页面所在目录下全名称

结果:/WEB-INF/page/hidden/hidden.jsp

6.request.getRequestURI()

结果:/Logistics/WEB-INF/page/hidden/hidden.jsp

 
原文地址:https://www.cnblogs.com/jskbk/p/6076340.html