【问题标题】:ServletContextListener Issue | HTTP Status 404 -ServletContextListener 问题 | HTTP 状态 404 -
【发布时间】:2013-05-03 20:04:29
【问题描述】:

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

web.xml

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

提醒.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 部分时,应用程序运行良好。 :-(

我做错了什么?

【问题讨论】:

  • 请发布整个 Reminder.class ,因为您发布的源代码现在无法编译

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


【解决方案1】:

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

如果它在默认包中,那么可能还有另一个问题。

【讨论】:

  • 它在默认包中。
  • contextInitialized方法中的“response”变量在哪里初始化?你确定它不为空吗?
  • +1 ; @user1640534:只是不要使用默认包,不鼓励使用 ts 并在 Tomcat 中导致一些副作用。
  • 试过换包了!但是,问题仍然存在!
猜你喜欢
  • 1970-01-01
  • 2020-03-27
  • 2018-03-05
  • 1970-01-01
  • 2015-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多