Java 名为 [/HelloServlet] 和 [com.sample.HelloServlet] 的 servlet 都映射到不允许的 url-pattern [/HelloServlet]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21071666/
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
The servlets named [/HelloServlet] and [com.sample.HelloServlet] are both mapped to the url-pattern [/HelloServlet] which is not permitted
提问by wormwood
I have made one particular project that having the error:
我做了一个有错误的特定项目:
Problem occured: Server Tomcat v7.0 Server at localhost failed to start.
出现问题:Server Tomcat v7.0 Server at localhost 启动失败。
When I try to start tomcat to run it. Here's my code. This was taken from the core servlets book.
当我尝试启动 tomcat 来运行它时。这是我的代码。这是从核心 servlets 书中获取的。
package com.sample;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
@WebServlet("/HelloServlet")
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public HelloServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello</H1>\n" +
"</BODY></HTML>");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
And this is the stacktrace:
这是堆栈跟踪:
Jan 12, 2014 1:36:39 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Java\jdk1.7.0_45\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Java/jdk1.7.0_45/bin/../jre/bin/client;C:/Java/jdk1.7.0_45/bin/../jre/bin;C:/Java/jdk1.7.0_45/bin/../jre/lib/i386;;.;C:\Java\jdk1.7.0_45\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32\wbem;C:\Windows\system32\windowspowershell\v1.0\;c:\program files\broadcom\broadcom 802.11 network adapter\driver;c:\program files\microsoft sql server0\tools\binn\;c:\program files\microsoft sql server0\dts\binn\;c:\program files\microsoft sql server0\tools\binn\vsshell\common7\ide\;c:\program files\microsoft visual studio 9.0\common7\ide\privateassemblies\;c:\program files\ibm\gsk8\lib;C:\PROGRA~1\IBM\SQLLIB\BIN;C:\PROGRA~1\IBM\SQLLIB\FUNCTION;C:\PROGRA~1\IBM\SQLLIB\SAMPLES\REPL;C:\MinGW\bin;;C:\jee_web_development\eclipse-jee-kepler-SR1-win32\eclipse;;.
Jan 12, 2014 1:36:39 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:test-app' did not find a matching property.
Jan 12, 2014 1:36:39 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:HelloServlet' did not find a matching property.
Jan 12, 2014 1:36:39 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Jan 12, 2014 1:36:39 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jan 12, 2014 1:36:39 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 465 ms
Jan 12, 2014 1:36:39 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 12, 2014 1:36:39 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.47
Jan 12, 2014 1:36:40 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloServlet]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/HelloServlet]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 6 more
Caused by: java.lang.IllegalArgumentException: The servlets named [/HelloServlet] and [com.sample.HelloServlet] are both mapped to the url-pattern [/HelloServlet] which is not permitted
at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:335)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2466)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2148)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2109)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2102)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2102)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1293)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:376)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5322)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Jan 12, 2014 1:36:40 PM org.apache.catalina.core.ContainerBase startInternal
SEVERE: A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:188)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1123)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.startup.Catalina.start(Catalina.java:691)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:800)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
Jan 12, 2014 1:36:40 PM org.apache.catalina.startup.Catalina start
SEVERE: The required Server component failed to start so Tomcat is unable to start.
org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.startup.Catalina.start(Catalina.java:691)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:732)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 7 more
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1131)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:302)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more
Jan 12, 2014 1:36:40 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
Jan 12, 2014 1:36:40 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Jan 12, 2014 1:36:40 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jan 12, 2014 1:36:40 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]
Jan 12, 2014 1:36:40 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]
I am new to sevlets and have no idea what most of the errors mean. What am I doing wrong? I have search for other questions like this on SO but the answers I found didn't work.
我是 sevlets 的新手,不知道大多数错误是什么意思。我究竟做错了什么?我在 SO 上搜索过类似的其他问题,但我发现的答案不起作用。
This is my web.xml file:
这是我的 web.xml 文件:
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>com.sample.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>/HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
I actually don't know what this is and what this for. But most project I imported have this So I just make one. Not sure if this is correct though.
我实际上不知道这是什么以及这是为了什么。但是我导入的大多数项目都有这个所以我只做一个。虽然不确定这是否正确。
采纳答案by Cesar Loachamin
It could be because you're mixing the web.xml servlets configuration with the annotation based configuration, so check that you don't declare the same servlet in the web.xml.
这可能是因为您将 web.xml servlet 配置与基于注释的配置混合在一起,因此请检查您没有在 web.xml 中声明相同的 servlet。
Based in your xml you have two options because you are configuring your servlet with annotations you can delete de tags from your web.xml. Or if you want to fix your web.xml you need to delete the start / from the servlet-name tag, it need to match with the before servlet name so:
根据您的 xml,您有两个选择,因为您正在使用注释配置 servlet,您可以从 web.xml 中删除 de 标签。或者,如果您想修复您的 web.xml,您需要从 servlet-name 标记中删除开始 /,它需要与之前的 servlet 名称匹配,因此:
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
回答by user3186704
You have to import "javax.servlet.annotation.WebServlet" to use @WebServlet("/HelloServlet") and you can use portable tomcat and check the port number of tomcat in server.xml file so that tomcat port does not conflict your existing port.
您必须导入“javax.servlet.annotation.WebServlet”才能使用@WebServlet("/HelloServlet") 并且您可以使用便携式tomcat并在server.xml文件中检查tomcat的端口号,以便tomcat端口不会与您现有的端口冲突港口。
回答by Srishti
Error: Tomcat Server failed to start
错误:Tomcat 服务器启动失败
Resolution:
解析度:
- Clean the workspace(It works many times
- Tomcat whle running directly points to the web.xml file.. Need to check what is written inweb.xml file....?his also turn out to be the server issue
- Sometimes it happens due to improper binding with jar files. For this first add manually jar file in to the WEB-INF ,lib folder and after that Right click on the project and Properties and then add the jar to the build path option.
- 清洁工作区(它可以工作很多次
- Tomcat运行时直接指向web.xml文件..需要检查web.xml文件中写的是什么..?他的也是服务器问题
- 有时是由于与 jar 文件绑定不当而发生的。为此,首先将 jar 文件手动添加到 WEB-INF ,lib 文件夹中,然后右键单击项目和属性,然后将 jar 添加到构建路径选项中。
Properly clean,build the workspace and then again try to start the server. It will work :)
正确清理,构建工作区,然后再次尝试启动服务器。它会工作:)
回答by Ashok AK
Server Tomcat v7.0 Server at localhost failed to start.
服务器 Tomcat v7.0 服务器在 localhost 启动失败。
In my eclipse (Juno) I fixed following ways.
在我的日食(朱诺)中,我修复了以下方法。
1.Clean project & server
1.清理项目和服务器
2.Remove .snapfile from following directory
2.取出.snap从以下目录中的文件
{workspace-directory}\.metadata\.plugins\org.eclipse.core.resources
{工作区目录}\.metadata\.plugins\org.eclipse.core.resources
OR
或者
3.Remove tempfile from following directory
3.从以下目录中删除临时文件
{workspace-directory}\.metadata\.plugins\org.eclipse.wst.server.core
{workspace-directory}\.metadata\.plugins\org.eclipse.wst.server.core