-
String getContextPath()
:返回上下文路径,例如:/hello -
String getQueryString()
:返回请求URL中的参数,例如:name=zhangSan -
String getRequestURI()
:返回请求URI路径,例如:/hello/oneServlet -
StringBuffer getRequestURL()
:返回请求URL路径,例如:http://localhost/hello/oneServlet,即返回除了参数以外的路径信息; -
String getServletPath()
:返回Servlet路径,例如:/oneServlet -
String getRemoteAddr()
:返回当前客户端的IP地址; -
String getRemoteHost()
:返回当前客户端的主机名,但这个方法的实现还是获取IP地址; -
String getScheme()
:返回请求协议,例如:http; -
String getServerName()
:返回主机名,例如:localhost -
int getServerPort()
:返回服务器端口号,例如:8080 -
得到项目的路径:
request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()
结果:http://localhost:8080/TEST
request获取上下文路径、URL、URI、Servlet路径等方法
最新推荐文章于 2020-11-13 17:06:24 发布