HttpServletRequest request=(HttpServletRequest)servletRequest;
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String remoteAddress=request.getRemoteAddr();
String servletPath=request.getServletPath();
String realPath=request.getRealPath("/");
String remoteUser=request.getRemoteUser();
String requestURI=request.getRequestURI();
System.out.println(path);
System.out.println(basePath);
System.out.println(remoteAddress);
System.out.println(servletPath);
System.out.println(realPath);
System.out.println(remoteUser);
System.out.println(requestURI);
输出为:
/ems_mvc
http://localhost:8080/ems_mvc/
0:0:0:0:0:0:0:1
/system/login.action
D:\tomcat\apache-tomcat-7.0.26.01\webapps\ems_mvc\
null
/ems_mvc/system/login.action
request.getHeader(arg0) 这个方法中可以得到浏览器的信息,以及请求信息。
host:
localhost:8080
user-agent:
Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0
accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
accept-language:
zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
accept-encoding:
gzip, deflate
referer:
http://localhost:8080/ems/system/main/loadSysInfo.action
cookie:
JSESSIONID=E0240CD74ABF5045835F90FBAE4717CC
connection:
keep-alive