struts2.1 获取项目路径:

在action中获取:

public static String SYSTEMREALPATH = "";


public static String path() {

ServletContext sc = (ServletContext) ActionContext.getContext().get(

ServletActionContext.SERVLET_CONTEXT);

SYSTEMREALPATH = sc.getRealPath("/");

SYSTEMREALPATH = SYSTEMREALPATH.replace("\\", "/");

if (!SYSTEMREALPATH.endsWith("/")) {

SYSTEMREALPATH = (new StringBuilder(String.valueOf(SYSTEMREALPATH)))

.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");

}