严重:为servlet分配异常< myservlet-name> java.lang.ClassNotFoundException:< myservlet>例外 [英] SEVERE: Allocate exception for servlet <myservlet-name> java.lang.ClassNotFoundException: <myservlet> exception

查看:3143
本文介绍了严重:为servlet分配异常< myservlet-name> java.lang.ClassNotFoundException:< myservlet>例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用以下 web.xml 时,我的项目运行正常,我可以通过index.jsp页面看到Hello World。我使用 Netbeans 7.4 Apache tomcat 6.0.41

When I use the following web.xml, my project runs fine and I can see "Hello World" getting displayed via index.jsp page. I am using Netbeans 7.4 and Apache tomcat 6.0.41

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
 </web-app>

然而,当我创建自己的servlet并使用以下 web.xml时,=

However, when I created my own servlet and use the following web.xml,=

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

 <servlet>
    <servlet-name>TEST_Authenticate</servlet-name>
    <servlet-class>restapi.TEST_Authenticate</servlet-class>
</servlet>  
<servlet-mapping>
    <servlet-name>TEST_Authenticate</servlet-name>
    <url-pattern>/TEST_Authenticate</url-pattern>
</servlet-mapping>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>


    <scope>provided</scope>
</dependency>

我最终得到以下信息Apache Tomcat日志中的错误:

I end up getting the following error in the Apache Tomcat Log:

Jul 24, 2014 9:36:14 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet TEST_Authenticate
java.lang.ClassNotFoundException: TEST_Authenticate
    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.StandardWrapper.loadServlet(StandardWrapper.java:1128)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:744)

我检查了以下 post 但仍然收到错误。

I have checked the following post but still getting the errors.

项目结构:

解决方案

首先删除

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
    <scope>provided</scope>
</dependency>

并将其放入在 pom.xml 中,如果它是Maven项目。

from the web.xml and put it in your pom.xml if it is a Maven project.

其次, ClassNotFoundException <在指定位置找不到类时抛出/ code>。在你的情况下,因为你有

Secondly, ClassNotFoundException is thrown when the class cannot be found in the specified location. In your case, as you have

<servlet-class>restapi.TEST_Authenticate</servlet-class>

所以,我假设你有一个名为 restapi的包并且您拥有该类 TEST_Authenticate

So, I am assuming that you have a package of name restapi and under which you have the class TEST_Authenticate.

所以,如果它是Maven项目
你应该有 scr / main / java / yourpackagename / yourClass 如果它是一个简单的web项目那么它应该像 src / yourpackagename / yourClass

So, if it is a Maven project you should have scr/main/java/yourpackagename/yourClass and if it is a simple web-project then it should be like src/yourpackagename/yourClass.

这篇关于严重:为servlet分配异常&lt; myservlet-name&gt; java.lang.ClassNotFoundException:&lt; myservlet&gt;例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆