java 启动Tomcat WAR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16407603/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:51:56  来源:igfitidea点击:

Start Tomcat WAR

javatomcatservlets

提问by F3RN1

I have installed a Tomcat server on my PC.

我已经在我的 PC 上安装了一个 Tomcat 服务器。

I have created a set of servlets in Eclipse and I exported in WAR format

我在 Eclipse 中创建了一组 servlet,并以 WAR 格式导出

When I deploy to the server and give it to boot I get the following error:

当我部署到服务器并让它启动时,我收到以下错误:

FALLO - No se pudo arrancar la aplicación en trayectoria de contexto /Middleware
FALLO - Encontrada excepción org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Middleware]]

If I go to the Tomcat log file for more details see the following:

如果我转到 Tomcat 日志文件以获取更多详细信息,请参阅以下内容:

Caused by: java.lang.IllegalArgumentException: The servlets named [reunionServlet] and [servlet.ReunionServlet] are both mapped to the url-pattern [/ReunionServlet] which is not permitted
at org.apache.catalina.deploy.WebXml.addServletMapping(WebXml.java:335)
at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2457)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2139)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2100)
at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2093)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1300)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:878)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:369)
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:5269)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

What is the problem?

问题是什么?

Do not know if the problem is with the file web.xml. Its content is as follows

不知道是不是web.xml文件的问题。其内容如下

enter image description here

在此处输入图片说明

回答by javadev

Both of reunionServlet and servlet.ReunionServlet are mapped to the same URL-PATTERN /ReunionServlet, which is prohibited in a Servlet Container. Remove one of the declarations.

reunionServlet 和 servlet.ReunionServlet 都映射到同一个 URL-PATTERN /ReunionServlet,这在 Servlet Container 中是被禁止的。删除其中一项声明。

回答by Olaf Kock

Read the first three lines of your stacktrace, they tell you quite well what's going on: As javadev has answered correctly, you're mapping two servlets to the same URL-pattern. One of them is obviously in your web.xml, the other most likely in some annotation (as the third line of your stacktrace gives away).

阅读堆栈跟踪的前三行,它们很好地告诉您发生了什么:由于 javadev 已正确回答,您将两个 servlet 映射到相同的 URL 模式。其中一个显然在您的 web.xml 中,另一个最有可能在某个注释中(因为堆栈跟踪的第三行给出了)。

Locate the offending servlet and change either the annotation or the web.xml declaration and you'll be fine.

找到有问题的 servlet 并更改注释或 web.xml 声明,您会没事的。

Funny enough: The offending servlet seems to be the same in both cases - e.g. you have declared the mapping for ReunionServlet in web.xml and annotated servlet.ReunionServlet (your package name seems to be "servlet" - quite generic). So you basically just need to delete one of the two declarations and everything should work as expected.

有趣的是:在这两种情况下,有问题的 servlet 似乎是相同的——例如,您已经在 web.xml 中声明了 ReunionServlet 的映射,并带有注释的 servlet.ReunionServlet(您的包名似乎是“servlet”——非常通用)。所以你基本上只需要删除两个声明之一,一切都应该按预期工作。

回答by Gabriel Marques

if ure using java ee api library the problem might be there. try to remove java EE 6 api library from the proyect and build again.

如果你使用 java ee api 库,问题可能就在那里。尝试从项目中删除 java EE 6 api 库并重新构建。

it works for me

这个对我有用