Java 为什么赢了';t spring mvc dispatcherservlet启动?

Java 为什么赢了';t spring mvc dispatcherservlet启动?,java,web-applications,spring-mvc,Java,Web Applications,Spring Mvc,我只是想设置我的第一个SpringMVC应用程序,这样我就可以使用这个框架了 然而,转到这个url:localhost:8080/springmvctest/home,我得到一个404错误。然而,转到localhost:8080/springmvctest,我确实看到了欢迎页面(index.jsp) 我做错了什么 Web.xml <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java

我只是想设置我的第一个SpringMVC应用程序,这样我就可以使用这个框架了

然而,转到这个url:localhost:8080/springmvctest/home,我得到一个404错误。然而,转到localhost:8080/springmvctest,我确实看到了欢迎页面(index.jsp)

我做错了什么

Web.xml

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>springmvctest</display-name>
  <servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/app-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping> 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
home.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello home!</h1>
    </body>
</html>
这种模式

<url-pattern>*.htm</url-pattern>
没有结束htm,因此它不是由spring的调度员执行的

解决方案:

改变

   <url-pattern>*.html</url-pattern>   
*.html

/*

在您的控件中使用

@RequestMapping(值={/home.htm',/index.htm},方法=RequestMethod.GET)

├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── something
│   │   │           └── springmvctest
│   │   │               ├── testclass.java
│   │   │               └── TestController.java
│   │   └── webapp
│   │       ├── index.jsp
│   │       └── WEB-INF
│   │           ├── app-config.xml
│   │           ├── jsp
│   │           │   └── home.jsp
│   │           └── web.xml
│   └── test
│       └── java
│           └── com
│               └── something
│                   └── springmvctest
<url-pattern>*.htm</url-pattern>
localhost:8080/springmvctest/home
   <url-pattern>*.html</url-pattern>   
   <url-pattern>/*</url-pattern>