1.发布到tomcat后获取应用的根目录
ServletContext s1=this.getServletContext();
String temp=s1.getRealPath("/");//C:Program FilesApache Software FoundationTomcat 7.0webappsdemo1
String temp=s1.getRealPath("/WEB-INF/classes/log4j.properties"); //C:Program FilesApache Software FoundationTomcat 7.0webappsdemo1WEB-INFclasseslog4j.properties