参考:https://blog.csdn.net/u010180031/article/details/52369537
https://blog.csdn.net/zmx729618/article/details/51395979?utm_source=blogxgwz3
1.request.getContextPath()
解释:拿到的是web项目的根路径,即 webContent (MyEclipse中是webRoot)
2. request.getSchema()
解释:返回的是当前连接使用的协议,一般应用返回的是http、SSL返回的是https;
3. request.getServerName()
解释:返回当前页面所在的服务器的名字,域名(xxx.com)
4. request.getServerPort()
解释:返回当前页面所在的服务器使用的端口,80;
5. request.getContextPath()
解释:返回当前页面所在的应用的名字。
6. getScheme()
解释:获取的是使用的协议(http 或https)
7. getProtocol()
解释:获取的是协议的名称(HTTP/1.11)
8. getLocalName
解释:获取到的是IP
9. getServletContext().getRealPath(“/”)
解释:获取“/”在机器中的实际地址
例如: 以访问的jsp为:http://localhost:8080/Testweb/jsp/index.jsp,工程名为/Testweb为例:
request.getContextPath(),得到工程名:/Testweb;
request.getServletPath(),返回当前页面所在目录下全名称:/jsp/index.jsp;
request.getRequestURL(),返回IE地址栏地址:http://localhost:8080/Testweb/jsp/index.jsp;
request.getRequestURI() ,返回包含工程名的当前页面全路径:Testweb/jsp/index.jsp;
request.getScheme(),获取到的确实http而不是https,与request.getRequestURL()拿到的一样也是http;