javaweb获取各种路径

 HttpServletResponse response = ServletActionContext.getResponse();  
        HttpServletRequest request = ServletActionContext.getRequest();  
String url = request.getScheme()+"://"+ request.getServerName()+request.getRequestURI()+"?"+request.getQueryString();  
System.out.println("获取全路径(协议类型://域名/项目名/命名空间/action名称?其他参数)url="+url);  
String url2=request.getScheme()+"://"+ request.getServerName();//+request.getRequestURI();  
System.out.println("协议名://域名="+url2);  


System.out.println("获取项目名="+request.getContextPath());  
System.out.println("获取参数="+request.getQueryString());  
System.out.println("获取全路径="+request.getRequestURL());  
request.getSession().getServletContext().getRealPath("/");//获取web项目的路径  
this.getClass().getResource("/").getPath()//获取类的当前目录  

你可能感兴趣的:(ssm)