我现在要做的是将servlet中dopost()方法中的代码移植到自己新创建的类里面,但是servlet获取tomcat容器的绝对路径在新建的类里面会报错,有什么方法可以等同于这个this.getServletContext().getRealPath("")方法,在新建的类里面使用
我的源码:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { Configuration cf = new Configuration();
String in = this.getClass().getClassLoader().getResource("FilePath.properties").getPath();

String url = cf.getValue(in, "key");//得到配置文件properties的路径并读取配置文件properties文件
File folder=new File(url);
File[] fileList = folder.listFiles();
//添加解压路径
String lsPath = this.getServletContext().getRealPath("/temp")+"\\";
String lsPath2 = this.getServletContext().getRealPath("/temp");
String a = "";
File fi = new File(lsPath);
List<String> listPath = new LinkedList<String>();

//找到zip压缩包文件
for(int i=0;i<fileList.length;i++){
String readFile = fileList[i].getName();
if(readFile.endsWith(".zip")){
if(!fi.exists()){
fi.mkdir();
}
//进行解压更新程序
//new Unzip().extZipFileList(fileList[i].getPath(), realPath);
new AntZip().unZip(fileList[i].getPath(), lsPath);
a=lsPath+"\\WEB-INF\\classes\\FilePath1.properties";
new AntZip().unZip(fileList[i].getPath(), cf.getValue(a, "key2"));
listPath.add(cf.getValue(a, "key2")+"\\WEB-INF\\classes\\FilePath1.properties");
// new DeleteFile();
// DeleteFile.delAllFile(lsPath);
// fileList[i].delete();

}
}
System.out.println("解压成功并zip压缩包被删除!!!");
TimeControl tc = new TimeControl();
tc.TimeTask(listPath);
}servlettomcatjavapropertiesstring