gpt4 book ai didi

java - 在 web.xml DD 中添加新的 servlet 时,Tomcat 7 拒绝在 Eclipse 上启动

转载 作者:行者123 更新时间:2023-11-30 09:23:48 24 4
gpt4 key购买 nike

在开发 Java EE 应用程序(学校练习)时,一切似乎都在正常工作。但是由于我在我的 eclipse 项目中添加了一个新的 servlet,我的 tomcat 拒绝启动并且重启过程超时。即使延长完成服务器操作的时间限制也无济于事。

这个问题似乎是由我的 web.xml 文件引起的,因为当我删除标签时,一切都像发条一样运行。虽然我可以通过右键单击它来启动我的 servlet,但这不是目的。我需要这个 web.xml 才能工作,以便使用带有 URL 模式的 jsp 调用我的 servlet。

日志只显示Server准备启动,没有报错那里。如果您不介意看一下,这是给我带来麻烦的代码。我的 web.xml 填充了与这个完全相同的内容,并且没有一个阻止 tomcat 正常启动。

<servlet>
<servlet-name>BookYourFlightServlet</servlet-name>
<servlet-class>com.sdzee.servlets.BookYourFlightServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BookYourFlightServlet</servlet-name>
<url-pattern>/bookYourFlightServlet</url-pattern>
</servlet-mapping>

我还将我的项目移到了我的 Ubuntu 计算机上,以便在那里进行测试,但同样如此。

又失败了:这是日志报告:

avr. 10, 2013 9:28:25 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:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;.
avr. 10, 2013 9:28:25 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:pro' did not find a matching property.
avr. 10, 2013 9:28:25 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
avr. 10, 2013 9:28:25 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
avr. 10, 2013 9:28:25 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1015 ms
avr. 10, 2013 9:28:25 PM org.apache.catalina.core.StandardService startInternal
INFO: Démarrage du service Catalina
avr. 10, 2013 9:28:25 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.39
avr. 10, 2013 9:28:26 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Users\moi\Desktop\mes workspaces\WorkSpace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\pro\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
avr. 10, 2013 9:28:26 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[/pro]]
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
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$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/pro]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
... 7 more
Caused by: java.lang.IllegalArgumentException: The servlets named [BookFlightServlet] and [com.sdzee.servlets.BookFlightServlet] are both mapped to the url-pattern [/bookFlightServlet] 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.processAnnotationsFile(ContextConfig.java:2093)
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)
... 7 more

avr. 10, 2013 9:28:26 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$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
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:684)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
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)
... 7 more

avr. 10, 2013 9:28:26 PM org.apache.catalina.startup.Catalina start
SEVERE: Catalina.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:684)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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

avr. 10, 2013 9:28:26 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 745 ms

我的小服务程序:

package com.sdzee.servlets;

import java.io.IOException;
import com.sdzee.beans.ReservationBean;
import com.sdzee.dao.DAOFactory;
import com.sdzee.dao.UtilisateurDao;
import com.sdzee.forms.BookFlightForm;

@WebServlet("/bookFlightServlet")
public class BookFlightServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final String VIEW = "/WEB-INF/JSP/bookYourFlight.jsp";

public static final String ATT_BOOKING = "booking";
public static final String ATT_FORM = "form";
public static final String CONF_DAO_FACTORY = "daofactory";

private UtilisateurDao utilisateurDao;

// ========================================================================
public void init() throws ServletException {
/* Récupération d'une instance de notre DAO Utilisateur */
this.utilisateurDao = ((DAOFactory) getServletContext().getAttribute(
CONF_DAO_FACTORY)).getUtilisateurDao();
}

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

/* Affichage de la page d'inscription */
this.getServletContext().getRequestDispatcher(VIEW)
.forward(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

BookFlightForm form = new BookFlightForm(utilisateurDao);
/* Traitement de la requête et récupération du bean en résultant */

ReservationBean reservationBean = form.registerFlightMethod(request);

request.setAttribute(ATT_FORM, form);
request.setAttribute(ATT_BOOKING, reservationBean);

this.getServletContext().getRequestDispatcher(VIEW)
.forward(request, response);
System.out.println("Dopost method");

}

}

我的 Jsp 文件

<%@ page pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Book Flight</title>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link type="text/css" rel="stylesheet" href="styles/form.css" />
</head>
<body>
<form method="post" action="bookFlightServlet">
<fieldset>
<legend>Reservation</legend>
<p>You can book your flight with this form.</p>

<label for="country">Country <span class="requis">*</span></label>
<input type="text" id="country" name="country" value="<c:out value="${reservationBean.country}"/>" size="20" maxlength="60" />
<span class="erreur">${form.erreurs['country']}</span>
<br />

<label for="departureDay">Departure Date <span class="requis">*</span></label>
<input type="text" id="departureDay" name="departureDay" value="<c:out value="${reservationBean.departureDay}"/>" size="20" maxlength="60" />
<span class="erreur">${form.erreurs['departureDay']}</span>
<br />


<input type="submit" value="BOOK" class="sansLabel" />
<br />
<p class="${empty form.erreurs ? 'succes' : 'erreur'}">${form.resultat}</p>
</fieldset>
</form>
</body>
</html>

Web.xml文件

<servlet>
<servlet-name>BookFlightServlet</servlet-name>
<servlet-class>com.sdzee.servlets.BookFlightServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BookFlightServlet</servlet-name>
<url-pattern>/bookFlightServlet</url-pattern>
</servlet-mapping>

最佳答案

启动失败,因为这个异常。

The servlets named [BookFlightServlet] and [com.sdzee.servlets.BookFlightServlet] are both mapped to the url-pattern [/bookFlightServlet] which is not permitted

您无法使用 2 个 servlet 处理 HTTP 请求。为 servlet-name 标签使用唯一名称并将 URL 模式映射到单独的 servlet 类。您不能这样做的原因是没有办法同时跨 2 个 servlet 线程有意义地提交 HTTP 响应。

有一个related thread on SO有人犯了类似的错误。您也可以从中学习。

关于java - 在 web.xml DD 中添加新的 servlet 时,Tomcat 7 拒绝在 Eclipse 上启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15934260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com