日期:2014-05-17 浏览次数:21070 次
<%@ page contentType="text/html; charset=UTF-8"%> <?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html> <head> <title>新闻快讯</title> <link rel="stylesheet" type="text/css" href="CSS/styles.css"> </head> <body> 。。。。。。 <!--这是个需要生成的文件,当然你也可以生成html文件,但是需要注意乱码--> <jsp:include page="baseInfoMiddle.jsp"></jsp:include> 。。。。。。 </body> </html>
<!-- velocityEngine生成模板文件 -->
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<props>
<prop key="resource.loader">class</prop>
<prop key="class.resource.loader.class">
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
</prop>
<prop key="velocimacro.library"></prop>
</props>
</property>
</bean>
<!-- 定时器 -->
<!-- 要调用的工作类 -->
<bean id ="quartzJob" class ="com.tlt.app.util.QuartzJob">
<property name="velocityEngine" ref="velocityEngine" />
</bean>
<!-- 定义调用对象和调用对象的方法 -->
<bean id ="jobtask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 调用的类 -->
<property name="targetObject">
<ref bean="quartzJob" />
</property>
<!-- 调用类中的方法 -->
<property name="targetMethod">
<value>work</value>
</property>
</bean>
<!-- 定义触发时间 -->
<bean id ="doTime" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobtask" />
</property>
<!-- cron表达式 -->
<property name="cronExpression">
<!-- 每天凌晨4点触发
<value>0 0 4 * * ?</value>
-->
<!-- 每隔1分钟执行1次,为了测试 -->
<value>0 0/1 * * * ?</value>
</property>
</bean>
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers" >
<list>
<ref bean="doTime" />
</list>
</property>
</bean>
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import org.springframework.ui.velocity.VelocityEngineUtils;
public class QuartzJob {
VelocityEngine velocityEngine;
private int count;
public void work(){
////////////////////////////////////////////////////////////////////////////
//这里每个人的写法不同,但不管怎么样,目的只有一个:获得想要的数据。我这里是通过post请求返回数据后解析,最后把想要的数据填入下面的HashMap<String, String>中就ok了;当然你也可以从数据库中获取数据。
// System.out.println("----------开始HTTP连接----------");
// String url="http://XXX.XXX.XXX.XXX";
// WebClient client=new WebClient();
// String content="";
// try {
// content = client.getWebContentByPost(url,"action=login&loginname=13761083826&password=111111");
// content = new String(content.getBytes("iso-8859-1"),"UTF-8");
// System.out.println(content);
// client=null;
// } catch (IOException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
// System.out.println("----------结束HTTP连接----------");
// System.out.println("----------解析xml开始