【问题标题】:Why does my Spring MVC application not work when changing the server mapping?为什么我的 Spring MVC 应用程序在更改服务器映射时不起作用?
【发布时间】:2016-06-25 18:34:51
【问题描述】:

我正在开发 Pluralsight 上概述的 Spring MVC“FitnessTracker”应用程序。下面是我的“web.xml”文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
         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">

  <servlet>
    <servlet-name>fitTrackerServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/config/servlet-config.xml</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>fitTrackerServlet</servlet-name>
    <url-pattern>/FitnessTracker/*.html</url-pattern>
  </servlet-mapping>

  <display-name>Archetype Created Web Application</display-name>
</web-app>

以上使Tomcat产生一堆异常,以

开头
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)

但是当我将&lt;url-pattern&gt; 标记之间的内容更改为*.html 时,它工作正常。这是为什么呢?

注意:我的目标是在我输入 /FitnessTracker/greeting.html 而不是 /greeting.html 时尝试让我的应用程序的控制器运行。我正在使用 Intellij IDEA,并使用 Tomcat 7.0 作为我的服务器进行 Maven 项目。

【问题讨论】:

    标签: maven spring-mvc


    【解决方案1】:

    应用程序运行@http://localhost:9090/FitnessTracker/greeting.html URL。 FitnessTracker 是应用程序根上下文,greeting.html 映射到 Hello 控制器方法。请看下文。

    能否请您发布 web.xml 和控制器映射。

    【讨论】:

      【解决方案2】:

      原始代码运行在 URL - http://localhost:8080/FitnessTracker/greeting.html。所以我不确定你为什么需要为此更改 web.xml。

      您尝试使用的 URL 模式“/FitnessTracker/*.html”也是无效的。 更多细节在这里。 https://stackoverflow.com/a/5441862/6352160

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-07
        • 1970-01-01
        • 1970-01-01
        • 2014-05-15
        • 1970-01-01
        • 1970-01-01
        • 2016-01-31
        • 2020-07-11
        相关资源
        最近更新 更多