struts2之路径问题

1.费话不说,我的项目名称为zzcz99,先看代码:

 

String baseContextPath = ServletActionContext.getRequest().getContextPath() + "/";   
String baseFullCxtPath = ServletActionContext.getServletContext().getRealPath("/");   
  
System.out.println("baseContextPath:"+baseContextPath);   
System.out.println("baseFullCxtPath:"+baseFullCxtPath);  

 

2.看输出:

 

baseContextPath:/zzcz99/   
baseFullCxtPath:D:\greensoft\apache-tomcat-6.0.16\webapps\zzcz99\

 

3.再看看如何获取网站根目录吧:

 

public static String getSiteBasePath(){   
    HttpServletRequest request = Struts2Utils.getRequest();   
    String path = request.getContextPath();   
    String basePath = request.getScheme()+"://" + request.getServerName() + ":" + request.getServerPort() + path + "/";   
    return basePath;           
}  

 

你可能感兴趣的:(apache,tomcat)