【问题标题】:Deploying the java web application. some listenerStart error部署 Java Web 应用程序。一些 listenerStart 错误
【发布时间】:2011-11-07 23:11:48
【问题描述】:

我有下一个问题: 我正在尝试使用 jre 6.0 在我的 Tomcat 7.0 上部署应用程序...我创建了一个名为 ListenerTester 的 servlet:

    package com.example;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

class ListenerTester extends HttpServlet {

    public void doGet (HttpServletRequest request, HttpServletResponse response) 
        throws IOException, ServletException {

            response.setContentType("text/html");           
            PrintWriter out = response.getWriter();

            out.println("text context attributes set by listener<br />");
            out.println("<br />");

            Dog dog = (Dog) getServletContext().getAttribute("dog");

            out.println("The dog`s breed is: " + dog.getBreed());

        }


    }

狗类是一个简单的类,它只有一个字段Stringbreed和getter以及带有参数的Constructor。

下一个类是 MyServletContextListener:

   package com.example;

import javax.servlet.*;

class MyServletContextListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent e) {

        ServletContext sc = e.getServletContext();

        String dogBreed = sc.getInitParameter("breed");
        Dog f = new Dog(dogBreed);      
        sc.setAttribute("dog", f);

    }

    public void contextDestroyed(ServletContextEvent e) {



    }

}

它们位于名为 com.example 的包中。应用程序的顶层文件夹是 listenerTester。

web.xml:

    <?xml version="1.0" encoding="UTF-8"?>  

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
  version="3.0" >  

<servlet>
    <servlet-name>ListenerTester</servlet-name>
    <servlet-class>com.example.ListenerTester</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>ListenerTester</servlet-name>
    <url-pattern>/ListenTest.do</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>breed</param-name>
    <param-value>Sparky</param-value>
</context-param>

<listener>
    <listener-class>com.example.MyServletContextListener</listener-class>
</listener>
</web-app>

问题是下一个 - 当我尝试运行它时 - 浏览器没有显示任何东西......根本......没有错误或任何东西。

When I look inside the catalina log file:

    08.11.2011 0:23:56 org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
08.11.2011 0:23:56 org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
08.11.2011 0:23:56 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 331 ms
08.11.2011 0:23:56 org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
08.11.2011 0:23:56 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.8
08.11.2011 0:23:56 org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory listenerTest
08.11.2011 0:23:56 org.apache.catalina.core.StandardContext startInternal
**SEVERE**: Error listenerStart
08.11.2011 0:23:56 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/listenerTest] startup failed due to previous errors
08.11.2011 0:23:56 org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-bio-8080"]
08.11.2011 0:23:56 org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
08.11.2011 0:23:56 org.apache.catalina.startup.Catalina start
INFO: Server startup in 233 ms

你能告诉我该怎么做吗?错误是什么?什么是 listenerStart?

【问题讨论】:

  • 您需要查看 catalina.out 文件以获得更详细的日志。

标签: java jakarta-ee tomcat servlets


【解决方案1】:

你应该让你的类公开而不是包私有。

【讨论】:

  • 非常感谢 - 这是问题的原因。我检查了 localhost 日志 - 那里写着 Tomcat 由于默认修饰符而无法创建 ServletContextListener。
猜你喜欢
  • 2017-12-20
  • 1970-01-01
  • 2020-12-17
  • 2023-03-27
  • 2017-02-13
  • 2011-02-08
  • 2018-10-11
  • 2011-10-24
  • 2016-04-19
相关资源
最近更新 更多