?? 定時(shí)器.txt
字號(hào):
xml中
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE web-app (View Source for full doctype...)>
- <web-app>
<display-name>struts</display-name>
- <filter>
<filter-name>encodingFilter</filter-name>
<filter-class>cn.spoto.ZhEncoderFilter</filter-class>
- <init-param>
<param-name>encode</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
- <filter-mapping>
<filter-name>encodingFilter</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
- <filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
- <listener>
<listener-class>cn.spoto.TopicListener</listener-class>
</listener>
- <servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
- <init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
- <init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
- <init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
- <servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
- <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
- <taglib>
<taglib-uri>bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
- <taglib>
<taglib-uri>html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
- <taglib>
<taglib-uri>logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
- <taglib>
<taglib-uri>nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>
- <taglib>
<taglib-uri>template.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-template.tld</taglib-location>
</taglib>
- <taglib>
<taglib-uri>tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
</taglib>
</web-app>
package cn.spoto;
import hibernate.TopicOperate;
import java.util.TimerTask;
import javax.servlet.ServletContext;
public class MyTimerTask extends TimerTask {
private ServletContext servletContext = null;
TopicOperate to = new TopicOperate();
public MyTimerTask(ServletContext servletContext) {
this.servletContext=servletContext;
}
@Override
public void run() {
servletContext.setAttribute("topics2", to.queryAll2());
}
}
package cn.spoto;
import java.util.List;
import java.util.Timer;
import hibernate.TopicOperate;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class TopicListener implements ServletContextListener{
Timer timer = new Timer(true);
public void contextInitialized(ServletContextEvent arg0) {
timer.schedule(new MyTimerTask(arg0.getServletContext()),0,5000);
}
public void contextDestroyed(ServletContextEvent arg0) {
timer.cancel();
}
}
package cn.spoto;
import java.util.Timer;
//import hibernate.TopicOperate;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class TopicListener implements ServletContextListener{
Timer timer = new Timer(true);
public void contextInitialized(ServletContextEvent event) {
//timer.schedule(new MyTimerTask(event.getServletContext()),0,5000);
//timer.schedule(new MyTimer(event.getServletContext()),0,5000);
timer.schedule(new MyTimer2(event.getServletContext()),0,60000);
}
public void contextDestroyed(ServletContextEvent arg0) {
timer.cancel();
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -