Spring MVC form action POST-Methode nicht umleiten

Ich bin in der Lage zu zeigen meine form aus meiner Studentenzeit.jsp-Datei und wenn ich auf den submit-button, soll umgeleitet werden zu den wichtigsten.jsp-Datei mit den Ergebnissen der Eingänge habe ich auf der vorherigen Seite, dh. in der form. Aber die wichtigsten.jsp-Seite wird nicht angezeigt, sondern ich bin immer ein 404.

Hier ist die NoticesController.java:

package com.mvc.spring;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class NoticesController {

    @RequestMapping(value = "/student", method = RequestMethod.GET)
    public String showHello(Model model)
    {
        return "student";
    }

    @RequestMapping(value = "/main", method = RequestMethod.POST)
    public String form(@ModelAttribute("StudentModel") Student student, Model model)
    {
        System.out.println("Inside form");
        model.addAttribute("Student", student);
        return "main";
    }

}

Dies ist Student.java:

package com.mvc.spring;

import org.springframework.stereotype.Controller;


public class Student {

    private int id;
    private String name;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }


}

Dies ist mein Schüler.jsp:

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>

<html>
<head>
<title>This is student.jsp</title>
</head>
<body>
    <form action="main.jsp" method="POST">
        ID: <input type="text" name="id"><br /> 
        Name: <input type="text" name="name" /> 
        <input type="submit" value="Submit" />

    </form>
</body>
</html>

Dies ist mein main.jsp:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Using GET and POST Method to Read Form Data</title>
</head>
<body>
    <p>${Student.id}</p>
    <p>${Student.name}</p>
</body>
</html>

Dies ist mein 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_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>WebMVC</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>notices</display-name>
    <servlet-name>notices</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>notices</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <description>Spring Tutorial</description>
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/spring</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

Dies ist mein notices-servlet.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"
    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">


    <context:component-scan base-package="com.mvc.spring"></context:component-scan>
    <mvc:annotation-driven></mvc:annotation-driven>
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        id="jspViewResolver">
    <property name="prefix" value="/WEB-INF/jsps/"></property>
    <property name="suffix" value=".jsp"></property>
    </bean>
</beans>

Dies ist der log:

org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/notices/] in DispatcherServlet with name 'notices'
Schreibe einen Kommentar