java 错误:包装器找不到 servlet 类 VendorRegistration 或其依赖的类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5155602/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Wrapper cannot find servlet class VendorRegistration or a class it depends on
提问by Swami
I'm a newb whose also been searching for a solution to the same problem. I've followed the steps that the Elite Gentleman and Bozho outlined here. So first of all, thanks a lot guys. But I still seem to have the same problem. Now as per my understanding and implementation, my situation is as follows:
我是一个新手,他也在寻找同样问题的解决方案。我已按照 Elite Gentleman 和 Bozho在此处概述的步骤进行操作。首先,非常感谢大家。但我似乎仍然有同样的问题。现在根据我的理解和实现,我的情况如下:
My servlet class VendorRegistration is available in the folder: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\VendorReg\WEB-INF\classes
我的 servlet 类 VendorRegistration 位于以下文件夹中:C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\VendorReg\WEB-INF\classes
My web.xml is present at: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\VendorReg\WEB-INF\
我的 web.xml 位于:C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\VendorReg\WEB-INF\
However, I still seem to be getting the error:
但是,我似乎仍然收到错误消息:
****HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Wrapper cannot find servlet class VendorRegistration or a class it depends on****
****HTTP 状态 500 - 类型异常报告消息描述服务器遇到内部错误 (),阻止它完成此请求。异常 javax.servlet.ServletException: Wrapper 找不到 servlet 类 VendorRegistration 或它依赖的类****
I have also appended my web.xml file below for your consideration:
我还在下面附加了我的 web.xml 文件供您考虑:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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_2_5.xsd"
version="2.5">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>VendorRegistration</servlet-name>
<servlet-class>VendorRegistration</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VendorRegistration</servlet-name>
<url-pattern>/VendorRegistration</url-pattern>
</servlet-mapping>
</web-app>
I am trying to access the servlet through the URL: http://localhost:8080/VendorReg/VendorRegistration. What am I missing ? I had compiled the .class file sometime before I installed Apache. And hence directly copied pasted the class file in the folder. Could that be a problem ?
我正在尝试通过 URL 访问 servlet:http://localhost:8080/VendorReg/VendorRegistration。我错过了什么?在安装 Apache 之前,我已经编译了 .class 文件。因此直接复制粘贴文件夹中的类文件。这可能是个问题吗?
回答by BalusC
The servlet or one of its dependencies is missing in the classpath.
类路径中缺少 servlet 或其依赖项之一。
First of all, always put Java classes in a package, also servlets. Packageless classes are invisible to classes in a normal package. For servlets, this works in specific environments only. You don't want to be dependent on that.
首先,始终将 Java 类放在一个包中,还有 servlet。无包类对于普通包中的类是不可见的。对于 servlet,这仅适用于特定环境。你不想依赖它。
package com.example;
public class VendorRegistration extends HttpServlet {
// ...
}
With this package, the compiled .class
file must end up in /WEB-INF/classes/com/example/VendorRegistration.class
. Don't forget to alter the associated <servlet-class>
entry in web.xml
accordingly.
使用这个包,编译后的.class
文件必须以/WEB-INF/classes/com/example/VendorRegistration.class
. 不要忘记相应地更改关联的<servlet-class>
条目web.xml
。
<servlet>
<servlet-name>VendorRegistration</servlet-name>
<servlet-class>com.example.VendorRegistration</servlet-class>
</servlet>
If that doesn't help, then you should put the classes or JAR files containing the (in)direct classes which are specified in any of the servlet's import
statements also in /WEB-INF/classes
(for .class
files) or /WEB-INF/lib
(for JAR files). The root cause in the exception stacktrace should tell which class exactly it is. Just read the stacktrace.
如果这没有帮助,那么您应该将包含在任何 servletimport
语句中指定的(in)直接类的类或 JAR 文件也放在/WEB-INF/classes
(对于.class
文件)或/WEB-INF/lib
(对于 JAR 文件)中。异常堆栈跟踪中的根本原因应该告诉它到底是哪个类。只需阅读堆栈跟踪。
See also:
也可以看看:
- Servlets info page- contains a Hello World and several useful links
- Servlets 信息页面- 包含一个 Hello World 和几个有用的链接
回答by Anoop Nyati
From tomcat 6.0 onwards, there is change in <url-pattern>
从 tomcat 6.0 开始,有变化 <url-pattern>
<servlet>
<servlet-name>VendorRegistration</servlet-name>
<servlet-name>VendorRegistration</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>VendorRegistration</servlet-name>
<url-pattern>/servlets/servlet/VendorRegistration</url-pattern>
</servlet-mapping>
It worked in my case!
它在我的情况下有效!
回答by Sebastian Ortiz
In my case the problem started when I made a copy/paste of HelloWorld.java class example from another project. Finally I solved it out by simply creating a new package, then a new HelloWorld.java from scratch and copy just the code for the doGet()
method.
在我的情况下,当我从另一个项目复制/粘贴 HelloWorld.java 类示例时,问题就开始了。最后,我通过简单地创建一个新包,然后从头开始创建一个新的 HelloWorld.java 并仅复制该doGet()
方法的代码来解决它。
Then I restarted the server and ran http://localhost:8080/mltest/HelloWorld
然后我重新启动服务器并运行http://localhost:8080/mltest/HelloWorld
And it worked!
它奏效了!
回答by Tapeshvar
I faced the same problem too. Actually one of my program which was working already after few changes showed me this error. I even did undo to revert the changes, still It happened to me. Finally I found a working solution for this for my scenario.
我也面临同样的问题。实际上,我的一个程序在经过几次更改后已经开始运行,向我显示了这个错误。我什至没有撤消以恢复更改,但它仍然发生在我身上。最后,我为我的场景找到了一个可行的解决方案。
SIMPLE:
简单的:
1.Just try to clean your project and run again. If it shows the same error and if you are sure there isn't any problem with your code then,
1. 尝试清理您的项目并再次运行。如果它显示相同的错误并且您确定您的代码没有任何问题,那么,
2.Enable the "Build Automatically" menu item under "Project" menu and try to clean your project. This time it worked for me.
2.启用“项目”菜单下的“自动构建”菜单项并尝试清理您的项目。这次对我有用。
Heard this is because when we make some changes and run, eclipse does some changes in its background too. So even if we revert the changes, eclipse might have not reverted the changes which it did in background. So performing these 2 steps will make sure it matches with the user change with its background change.
听说这是因为当我们做一些更改并运行时,eclipse也在其后台进行了一些更改。因此,即使我们还原更改,eclipse 也可能不会还原它在后台所做的更改。因此,执行这两个步骤将确保它与用户更改及其背景更改相匹配。
Hope it helps and solves your problem too.
希望它也能帮助并解决您的问题。
回答by James.Ji
This is how I solved the problem when I had the same exception with yours.
当我遇到与您相同的异常时,这就是我解决问题的方法。
Ensure you add the right libraries, we need to add the Library Tomcat. At the beginning, I just added the servlet-api.jar, but someone told me it's not a right way. Maybe when you implemented the project in tomcat it had some Conflicts with Tomcat.
Ensure your project in the right folder,
%Tomcat_HOME%\webapps\%projectName\WEB-INF\classes\.....
Ensure web.xml in the right folder, and with right form,
%Tomcat_HOME%\webapps\%projectName\WEB-INF\web.xml
Reload the application in Tomcat.
Access the servlet through URL:
http://localhost:port/%projectName%
确保您添加了正确的库,我们需要添加库 Tomcat。一开始,我只是添加了servlet-api.jar,但有人告诉我这不是一个正确的方法。也许当你在 tomcat 中实现该项目时,它与 Tomcat 有一些冲突。
确保您的项目在正确的文件夹中,
%Tomcat_HOME%\webapps\%projectName\WEB-INF\classes\.....
确保 web.xml 位于正确的文件夹中,并具有正确的格式,
%Tomcat_HOME%\webapps\%projectName\WEB-INF\web.xml
在 Tomcat 中重新加载应用程序。
通过 URL 访问 servlet:
http://localhost:port/%projectName%
回答by Di_Di
I'm afraid you made a mistake to try to access a servlet class directly.
恐怕您在尝试直接访问 servlet 类时犯了一个错误。
Generally, the URL should be your any txt, jsp, html files under your application folder , but the servlet is used for response your "POST" or "Get" request from client side, it's immpossible to access it directly through URL.
通常,URL 应该是您的应用程序文件夹下的任何 txt、jsp、html 文件,但是 servlet 用于响应来自客户端的“POST”或“Get”请求,无法通过 URL 直接访问它。