HTTP 状态 404 - /EmployeeInfoSubmitPg/addEmployee

HTTP Status 404 - /EmployeeInfoSubmitPg/addEmployee

尝试使用 Spring MVC 制作简单的网络应用程序。我在其中尝试提交员工信息,它应该向我显示信息已提交的消息。但是,它显示 404 错误如下:

HTTP Status 404 - /EmployeeInfoSubmitPg/addEmployee
type Status report
message /EmployeeInfoSubmitPg/addEmployee
description The requested resource is not available.
Apache Tomcat/7.0.67

1) 这是 EmployeeController.java :-

package com.SpringMVC.Employees;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class EmployeesController {

    @RequestMapping(value = "/employee", method= RequestMethod.GET)
    public ModelAndView employee() {
        return new ModelAndView("employee", "command", new Employee());
    }

    @RequestMapping(value = "/addEmployee", method= RequestMethod.POST)
    public String addEmployee(@ModelAttribute("SpringMVC_EmployeesInfoSubmitPg")Employee employee, ModelMap model) {
        model.addAttribute("name", employee.getName());
        model.addAttribute("age", employee.getAge());
        model.addAttribute("id", employee.getId());
        return "result";
    }
}

2)在Employee.java中,我简单定义了name、age、id等私有字段,并为私有字段定义了getters和setters方法。

3)这是web.xml :-

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee           http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>SpringMVC form of Employees Info.</display-name>

    <servlet>
        <servlet-name>EmployeeInfoSubmitPg</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>EmployeeInfoSubmitPg</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

4) 这是 EmployeeInfoSubmitPg-servlet.xml :-

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
   http://www.springframework.org/schema/beans     
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.SpringMVC.Employees" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>

5) 这是 employee.jsp :-

    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<title>SpringMVC form of Employees Info.</title>
</head>
<body>
    <h2>Employee Information</h2>
    <form:form method="POST" action="/EmployeeInfoSubmitPg/addEmployee">
        <table>
            <tr>
                <td><form:label path="name">Name</form:label></td>
                <td><form:input path="name" /></td>
            </tr>
            <tr>
                <td><form:label path="age">Age</form:label></td>
                <td><form:input path="age" /></td>
            </tr>
            <tr>
                <td><form:label path="id">id</form:label></td>
                <td><form:input path="id" /></td>
            </tr>
            <tr>
                <td colspan="2"><input type="submit" value="Submit" /></td>
            </tr>
        </table>
    </form:form>
</body>
</html>

6) 这是 result.jsp :-

    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<title>SpringMVC form of Employees Info.</title>
</head>
<body>
    <h2>Submitted Employee Information</h2>
    <table>
        <tr>
            <td>Name</td>
            <td>${name}</td>
        </tr>
        <tr>
            <td>Age</td>
            <td>${age}</td>
        </tr>
        <tr>
            <td>ID</td>
            <td>${id}</td>
        </tr>
    </table>
</body>
</html>

form:form method="POST" action="./addEmployee">,像这样改变你的表单