直接上代码吧,高手们帮我看看
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5"> <listener>
<listener-class>test.timer.TimerListener</listener-class>
</listener> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>package test.timer;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;public class TimerListener implements ServletContextListener { @SuppressWarnings("unused")
private ServletContext servletContext = null;
private Timer timer = null; /**
* 开始执行
*/
@Override
public void contextInitialized(ServletContextEvent e) {
e.getServletContext().log("init !");
timer = new Timer(true);
// 获得当天的日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
Date date = new Date();
// 定义开始时间字符串
String timeStr = "12:00:00";
timeStr = sdf.format(date) + timeStr;
// 获得当天的指定时间的date对象
sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
date = sdf.parse(timeStr);
} catch (ParseException e1) {
e1.printStackTrace();
} // 判断今天的执行时间是否已经过去,如果过去则改为明天
if (date.getTime() < System.currentTimeMillis()) {
date = new Date(date.getTime() + 24 * 60 * 60 * 1000);
} timer.schedule(new TestTimer(), date, 24*60*60 * 1000); } /**
* 销毁
*/
@Override
public void contextDestroyed(ServletContextEvent e) {
timer.cancel();
e.getServletContext().log("destroyed");
}
}环境没有问题,如果web.xml去掉<listener>可以正常启动。项目就这么几个文件
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5"> <listener>
<listener-class>test.timer.TimerListener</listener-class>
</listener> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>package test.timer;import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;public class TimerListener implements ServletContextListener { @SuppressWarnings("unused")
private ServletContext servletContext = null;
private Timer timer = null; /**
* 开始执行
*/
@Override
public void contextInitialized(ServletContextEvent e) {
e.getServletContext().log("init !");
timer = new Timer(true);
// 获得当天的日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
Date date = new Date();
// 定义开始时间字符串
String timeStr = "12:00:00";
timeStr = sdf.format(date) + timeStr;
// 获得当天的指定时间的date对象
sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
date = sdf.parse(timeStr);
} catch (ParseException e1) {
e1.printStackTrace();
} // 判断今天的执行时间是否已经过去,如果过去则改为明天
if (date.getTime() < System.currentTimeMillis()) {
date = new Date(date.getTime() + 24 * 60 * 60 * 1000);
} timer.schedule(new TestTimer(), date, 24*60*60 * 1000); } /**
* 销毁
*/
@Override
public void contextDestroyed(ServletContextEvent e) {
timer.cancel();
e.getServletContext().log("destroyed");
}
}环境没有问题,如果web.xml去掉<listener>可以正常启动。项目就这么几个文件
解决方案 »
- oracle插入colb字段字符串长度超过4000问题
- java 的数组赋值
- 那里可以下到 三大框架(strut2+spring+hibernate) 项目视频
- 三层结构系统
- 关于对jfreechart的坐标轴字体的位置问题
- 请大家帮我看一下添加附件上传的问题。。很着急。。。。。
- WEBLOGIC加载JAR问题..
- 用什么方法能列出jndi某个目录下的所有ejb
- 请问老手我学过一些windows编程,现在想学网络的一些编程(比如j2ee等相关的)应从哪里开始。
- svnkit文件目录存在空格如何解决
- tomcat下项目运行缓慢的问题
- 用hibernate管理事务,先更新再查询时,更新不成功,郁闷。
2011-8-5 11:19:54 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\jdk 1.6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\jdk 1.6\jre\bin;D:/jdk 1.6/bin/client;D:/jdk 1.6/bin;D:/jdk 1.6/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\jdk 1.6\bin;D:\apache-tomcat-6.0.32\bin;C:\Program Files (x86)\Microsoft SQL Server\80\Tools\Binn\;D:\SQL 2005\Microsoft SQL Server\90\DTS\Binn\;D:\SQL 2005\Microsoft SQL Server\90\Tools\binn\;D:\SQL 2005\Microsoft SQL Server (x86)\90\Tools\binn\;D:\SQL 2005\Microsoft SQL Server (x86)\90\DTS\Binn\;D:\SQL 2005\Microsoft SQL Server (x86)\90\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies\;C:\Program Files (x86)\Common Files\Thunder Network\KanKan\Codecs;D:\mysql\mysql 64\bin
2011-8-5 11:19:54 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-81
2011-8-5 11:19:54 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 882 ms
2011-8-5 11:19:54 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2011-8-5 11:19:54 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.32
2011-8-5 11:19:54 org.apache.catalina.core.StandardContext listenerStart
严重: Error configuring application listener of class test.timer.TimerListener
java.lang.ClassNotFoundException: test.timer.TimerListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4148)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
2011-8-5 11:19:54 org.apache.catalina.core.StandardContext listenerStart
严重: Skipped installing application listeners due to previous error(s)
2011-8-5 11:19:54 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2011-8-5 11:19:54 org.apache.catalina.core.StandardContext start
严重: Context [] startup failed due to previous errors
2011-8-5 11:19:54 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-81
2011-8-5 11:19:55 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2011-8-5 11:19:55 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/62 config=null
2011-8-5 11:19:55 org.apache.catalina.startup.Catalina start
信息: Server startup in 529 ms
啊,你把项目重新编译,然后在web服务器上重新发布下.