ServletContextListener问题| HTTP状态404 -

时间:2013-05-09 11:01:27

标签: java servlets jdbc http-status-code-404 servletcontextlistener

据观察,每当我向Listener添加web.xml类时,整个Web应用程序就会停止运行。请找到以下代码:

的web.xml

 <listener>
    <listener-class>Reminder</listener-class>
</listener>

Reminder.java

@Override
public void contextInitialized(ServletContextEvent sce) {
    try {
        response.getWriter().print("Initasdadsa");
    } catch (IOException ex) {
        Logger.getLogger(Reminder.class.getName()).log(Level.SEVERE, null, ex);
    }
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        Driver driver = drivers.nextElement();
        try {
            DriverManager.deregisterDriver(driver);
        } catch (SQLException e) {
        }

    }
}

当我部署上述应用程序的.war文件时,它说:

HTTP Status 404 - type Status report
message description The requested resource is not available.Apache Tomcat/6.0.24

Tomcat日志文件如下:

May 9, 2013 3:57:10 PM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/CloudStorage]
May 9, 2013 3:57:10 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed         
to unregister it when the web application was stopped. To prevent a memory leak, the   
JDBC    Driver has been forcibly unregistered.
May 9, 2013 3:57:50 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive CloudStorage.war
May 9, 2013 3:57:50 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
May 9, 2013 3:57:50 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/CloudStorage] startup failed due to previous errors
May 9, 2013 3:57:50 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: A web application registered the JBDC driver [com.mysql.jdbc.Driver] but failed       
to unregister it when the web application was stopped. To prevent a memory leak, the 
JDBC Driver has been forcibly unregistered.

当我省略Listener部分时,应用程序运行正常。 : - (

我做错了什么?

1 个答案:

答案 0 :(得分:2)

除非您的类在默认包中,否则您需要在web.xml中提供Reminder类的完全限定名称,例如“com.example.Reminder”。

如果它在默认包中,则可能存在其他问题。