Java HTTP状态404请求的资源在Spring Mvc中不可用

Java HTTP状态404请求的资源在Spring Mvc中不可用,java,spring,spring-mvc,Java,Spring,Spring Mvc,我正在构建一个非常简单的Spring应用程序。我使用的是Spring工具套件3.6.4,Tomcat 8.0。但在访问/问候映射时,它会崩溃。它返回HTTP状态404-/FitnessTracker/greeting请求的资源不可用 应用程序没有调用控制器,因为控制台没有在System.out.println中显示任何内容。请帮帮我,我做错了什么 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2

我正在构建一个非常简单的Spring应用程序。我使用的是Spring工具套件3.6.4,Tomcat 8.0。但在访问/问候映射时,它会崩溃。它返回HTTP状态404-/FitnessTracker/greeting请求的资源不可用 应用程序没有调用控制器,因为控制台没有在System.out.println中显示任何内容。请帮帮我,我做错了什么

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>fitnessTrackerServlet</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>fitnessTrackerServlet</servlet-name>
        <url-pattern>*.html</url-pattern>

    </servlet-mapping>

    <display-name>Archetype Created Web Application</display-name>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

    <mvc:annotation-driven/>
    <context:component-scan base-package="com.thewizardofoz.controllers"/>


     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

</beans>
hello.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <h1>${greeting}</h1>
</body>
</html>

在此处插入标题
${问候语}

看起来您将servlet映射为处理
*.html
请求,但您试图请求的
/FitnessTracker/greeting
与您的格式不匹配

为什么不使用@RestController而不是@Controller?您不应该访问/greeting.html而不仅仅是“greeting”吗?您的上下文路径是什么?路径中的“FitnessTracker”部分是否不必要?您的项目名称是什么,您尝试请求哪个url?我理解您的观点,但我尝试了星号,/asterisks,/它返回另一个错误“非法参数”。另一方面,我正在做一个在线课程的练习,它与讲师展示的完全相同,没有任何错误。我对此感到失望。请尝试
@RequestMapping(value=“/greeting.html”)
-因为servlet的映射不会去掉结尾
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <h1>${greeting}</h1>
</body>
</html>