取应用上下文单例
ApplicationContext context = ApplicationContext.getInstance();
获取应用名称 context.getAppName();
获取应用工作路径 context.getApplicationWorkPath();
获取Home路径 context.getEOS_HOME();
获取应用配置文件夹路径(系统、用户) context.getApplicationConfigPath();
获取应用系统相关构件存储库路径 context.getApplicationSystemWorkingPath();
获取应用用户相关构件存储库路径 context.getApplicationUserWorkingPath();
获取应用EAR所在物理目录 context.getEarRealPath();
获取WAR所在目录 context.getWarRealPath();
例如
//模板路径
String modelPath = ApplicationContext.getInstance().getWarRealPath()+“upload”+File.separator+“temp”+File.separator+“tzd_zqcgfp.docx”;
//获取在web.xml中配置的路径
public static String getFileDir(String processinstid){
String url = "";
int dateTime =Integer.parseInt(getDateTime()) ;
String rtn = getTimeRtn(processinstid);
int intRtn = Integer.parseInt(rtn);
if(intRtn <= dateTime){
rtn = dateTime+"";
}
try{
String xmlUrl = ApplicationContext.getInstance().getWarRealPath() + "WEB-INF/web.xml";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File(xmlUrl));
NodeList list = doc.getElementsByTagName("context-param");
for(int i=0;i<list.getLength();i++){
Element element = (Element) list.item(i);
String name = element.getElementsByTagName("param-name").item(0).getFirstChild().getNodeValue();
if(name.equals("letterFileDir")){
url = element.getElementsByTagName("param-value").item(0).getFirstChild().getNodeValue();
break;
}
}
}catch(Exception e){
e.printStackTrace();
}
String fileDir = url+File.separator+rtn;
File tempDirPath =new File(fileDir);
if(!tempDirPath.exists()){
tempDirPath.mkdirs();
}
return fileDir;
}