HTTP状态404-找不到Spring MVC RequestMapping

时间:2018-10-20 23:23:39

标签: java spring-mvc annotations

我是Spring框架的新手。我收到以下错误。请帮助解决它。

http://localhost:9090/FitnessTracker/addMinutes

HTTP状态404-找不到

类型状态报告

找不到消息

说明请求的资源不可用。

GlassFish Server开源版4.1.2

下面是我的web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
    http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>Fitness Tracker</display-name>
    <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>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>fitTrackerServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

下面是我的servlet-config.xml

<?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-4.3.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-4.3.xsd">
    <mvc:annotation-driven/>
    <context:component-scan base-package="com.spring.controller"></context:component-scan>
<!--    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/Views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>  -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
    p:prefix="/WEB-INF/Views/" p:suffix=".jsp"/>
</beans>

下面是我的MinutesController.java

package com.spring.bankApp.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class MinutesController {

    @RequestMapping("/addMinutes")
    public String addMinutes(){
        return "addMinutes";
    }

}

下面是我的addMinutes.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>Add Minutes</title>
</head>
<body>
    <h1>Add Minutes Exercised</h1>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您确定您的“视图”目录中的大写字母是“ V”吗?

可能是问题