HTTP状态500 - 实例化由DeploymentDescriptorLoadException引起的servlet类时出错

时间:2015-12-06 02:33:14

标签: java maven tomcat servlets

我正在尝试自学servlet和Tomcat等。我在线学习了一些教程并尝试使用maven构建我的第一个servlet,然后我收到了这个错误:

type Exception report

message Error instantiating servlet class com.perficient.servlets.HelloWorld

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class com.perficient.servlets.HelloWorld
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)
root cause

java.lang.ClassNotFoundException: com.perficient.servlets.HelloWorld
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1858)
    org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1709)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.64 logs.

我在网上进行了一些研究,但没有一个答案解决了我的问题。我的项目树看起来像这样: Project Tree

问题说:

Description Resource    Path    Location    Type
CHKJ3000E: WAR Validation Failed: org.eclipse.jst.j2ee.commonarchivecore.internal.exception.DeploymentDescriptorLoadException: WEB-INF/web.xml  FirstWebapp     Unknown Validation Message

所以我认为web.xml一定有问题,但我不熟悉这个错误信息。这是我的web.xml:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <servlet>
        <servlet-name>HelloWorld</servlet-name>
        <servlet-class>com.perficient.servlets.HelloWorld</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>HelloWorld</servlet-name>
        <url-pattern>/HelloWorld</url-pattern>
    </servlet-mapping>
</web-app>

任何人都知道我的web.xml出了什么问题?非常感谢!

1 个答案:

答案 0 :(得分:1)

  

ClassNotFoundException:com.perficient.servlets.HelloWorld

  1. Tomcat无法找到您的HelloWorld类。确保在WEB-INF / classes中添加了com.perficient.servlets.HelloWorld

  2. 将映射更改为:

    <servlet-mapping>
            <servlet-name>HelloWorld</servlet-name>
            <url-pattern>/servlet/HelloWorld</url-pattern>
        </servlet-mapping>