java获取request中的各种路径

java从Request对象中可以获取各种路径信息:  

       假设请求的页面是index.jsp,项目是WebDemo,则在index.jsp中获取有关request对象的各种路径信息如下 

 

String path = request.getContextPath();  

path:/WebDemo  


String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 

basePath:http://localhost:8683/WebDemo/  

 

String remoteAddress=request.getRemoteAddr();  

remoteAddr:127.0.0.1  


String servletPath=request.getServletPath();  

servletPath:/index.jsp  


String realPath=request.getRealPath("/");  

realPath:D:\apache-tomcat-6.0.13\webapps\WebDemo\  


String remoteUser=request.getRemoteUser();  

remoteUser:null  


String requestURI=request.getRequestURI();  

requestURI:/WebDemo/index.jsp  



你可能感兴趣的:(java获取basePath)