HttpServletRequest的常见方法解释

  • getProtocol=HTTP/1.1 返回使用的协议名称和版本号
  • getScheme=http 返回使用的协议名
  • getServerName=localhost 返回服务器名,还比如www.baidu.com
  • getServerPort=8080 返回服务器端口号
  • getRemoteAddr=0:0:0:0:0:0:0:1 返回ip地址(注意如果请求经代理服务器转发的话,此方法返回的是代理服务器的ip地址)
  • getRemoteHost=0:0:0:0:0:0:0:1 返回客户端的主机名(注意如果web容器不能够或者为了提升性能不去解析的话会返回ip地址)
  • isSecure=false 是否是安全的链接(Https)
  • getRemotePort=61227 返回客户端发起请求的进程端口(或者代理服务器的端口)
  • getPathInfo=null 返回额外的url信息。比如请求路径是:”http://localhost:8080/fonlin/test?name=11“,然而应用中的servlet匹配的路径是”/fonlin/*”,那么这个方法就会返回”/test”,不包括之后的query部分。如果没有就返回null
  • getContextPath= 返回请求中对应context的部分,如果此context是默认context,则返回”“。
  • getRequestURI=/history/export 返回请求路径从端口之后到query部分之前的部分
  • getRequestURL=http://localhost:8080/history/export 返回一个完整的请求路径(不包括query部分)
  • getServletPath=/history/export 返回请求对应servlet的部分

猜你喜欢

转载自blog.csdn.net/opiqi/article/details/80905158