struts2.1 獲取項目路徑:java
在action中獲取:web
public static String SYSTEMREALPATH = "";spring
public static String path() {app
ServletContext sc = (ServletContext) ActionContext.getContext().get(ide
ServletActionContext.SERVLET_CONTEXT);ui
SYSTEMREALPATH = sc.getRealPath("/");spa
SYSTEMREALPATH = SYSTEMREALPATH.replace("\\", "/");xml
if (!SYSTEMREALPATH.endsWith("/")) {get
SYSTEMREALPATH = (new StringBuilder(String.valueOf(SYSTEMREALPATH)))it
.append("/").toString();
}
return SYSTEMREALPATH;
}
spring3.2 獲取項目路徑:
web.xml配置:
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>testOfSrpingWeb.root</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.WebAppRootListener</listener-class>
</listener>
在javabean中獲取:
public static String getPath() {
return System.getProperty("testOfSrpingWeb.root");
}