在web.xml DD中添加新的servlet时,Tomcat 7拒绝启动Eclipse [英] Tomcat 7 refuses to start on Eclipse when adding new servlet in web.xml DD

查看:172
本文介绍了在web.xml DD中添加新的servlet时,Tomcat 7拒绝启动Eclipse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发Java EE应用程序(学校练习)时,一切似乎都正常工作。但是因为我在我的eclipse项目中添加了一个新的servlet,我的tomcat拒绝启动,重启过程耗尽时间。甚至延长完成服务器操作的时间限制也没有帮助。

While developing a Java EE application (school exercise), everything seem to be working properly. But since i've added a new servlet on my eclipse project, my tomcat refuses to start and the restart process runs out of time. Even extending the time limit to complete server operations doesnt help neither.

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

This problem seem to be caused by my web.xml file because when i remove the tags , everything runs like a clockwork. Althoug I'm able to launch my servlet by right clicking on it but that is not the purpose. I need this web.xml to work in order to call my servlet with my jsp with the URL pattern.

日志只显示服务器准备的启动,但没有错误显示
那里。
如果您不介意看一下,这是我的代码,这会给我带来麻烦。
我的web.xml填充与此完全相同,但没有一个阻止tomcat正常启动。

The logs only show that the Server prepares for startup, but no error is shown there. If you dont mind taking a look, here is my the code that is causing me trouble. My web.xml is populated with exactly the same as this one and none of them are preventing tomcat to start properly.

<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计算机上,以便在那里进行测试但同样的事情。

I also moved my project to my Ubuntu computer in order to test it there but same thing.

再次失败:
这是日志报告:

It failed again : Here is the log report:

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

我的Servlet:

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 startup fails because of this exception.


名为[BookFlightServlet]和[com.sdzee.servlets.BookFlightServlet]的servlet都映射到url-pattern [/ bookFlightServlet],而不是允许

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类。你不能这样做的原因是没有办法在两个servlet线程上同时有意义地提交HTTP响应。

You cannot handle a HTTP request with 2 servlets. Use unique names for the servlet-name tags and map the URL patterns to separate servlet classes. The reason you cannot do this is that there is no way to meaningfully commit a HTTP response across 2 servlet threads at the same time.

有一个关于SO的相关主题,其中有人犯了类似的错误。你也可以从中学习。

There is a related thread on SO where someone makes a similar mistake. You can learn from that too.

这篇关于在web.xml DD中添加新的servlet时,Tomcat 7拒绝启动Eclipse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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