web项目中quartz使用request获取指定的文件路径
来源:互联网 发布:java join() 编辑:程序博客网 时间:2024/06/16 00:19
1.执行删除昨天的文件夹
public class CacheFileClaearJob implements Job,Runnable {
public void execute(JobExecutionContext context) throws JobExecutionException {
try {
ServletContext servletContext =(ServletContext)context.getScheduler().getContext().get("servletContext");
String realPath = servletContext.getRealPath("/").replace("\\", "/");
String oldTempateFile = realPath+"/template/"+StringUtil.dateFormat(DateUtils.getDate(-1), "yyyy-MM-dd");
File file = new File(oldTempateFile);
if(file.exists()){
FileUtil.deleteDir(file);
}
} catch (SchedulerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void run() {
System.out.println("i am here run!");
}
}
2.配置web启动监听器
public class QuartzListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
// TODO Auto-generated method stub
}
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
Scheduler sched = new StdSchedulerFactory().getScheduler();
sched.getContext().put("servletContext", servletContextEvent.getServletContext());
} catch (SchedulerException e) {
e.printStackTrace();
}
}
}
3.配置web. xml
<listener>
<listener-class>cn.com.jx.core.listener.QuartzListener</listener-class>
</listener><listener>
<listener-class>cn.com.jx.core.listener.QuartzListener</listener-class>
</listener>
- web项目中quartz使用request获取指定的文件路径
- web项目中quartz使用request获取指定的文件路径
- struts2中使用request &&取得web下项目路径
- Quartz-Java Web项目中使用Quartz
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- web项目中各种路径的获取
- 发刚刚覆盖非官方
- 【Git学习笔记】撤销修改
- 编译iOS使用的.a库文件
- 剑指offer面试题:输入某二叉树的前序遍历和中序遍历的结果,输出后序遍历结果。
- 去掉android屏幕上的title bar
- web项目中quartz使用request获取指定的文件路径
- QUST程序设计赛G题:占教室
- Openstack安装部署工具之Compass (一)
- delphi中ShellExecute使用详解
- 黄发刚刚覆盖非官方
- 入驻CSDN博客
- 好人难寻 A Good Man Is Hard to Find 弗兰纳里 奥康纳
- 血型统计
- .net4.5版本在提交web数据时,系统提示数据存在潜在的危险