Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring MVC web app中提交表单时出现错误404_Java_Spring_Jsp_Servlets_Spring Mvc - Fatal编程技术网

Java 在Spring MVC web app中提交表单时出现错误404

Java 在Spring MVC web app中提交表单时出现错误404,java,spring,jsp,servlets,spring-mvc,Java,Spring,Jsp,Servlets,Spring Mvc,我正在尝试SpringMVC表单处理的一个示例。在浏览器中运行时,单击页面中的“提交”按钮时,我得到以下信息: HTTP Status 404 - /HelloWeb/addStudent type Status report message /HelloWeb/addStudent description The requested resource is not available. 这是web.xml文件: 以下是JSP文件: student.jsp springmvc表

我正在尝试SpringMVC表单处理的一个示例。在浏览器中运行时,单击页面中的“提交”按钮时,我得到以下信息:

HTTP Status 404 - /HelloWeb/addStudent

type Status report

message /HelloWeb/addStudent

description The requested resource is not available.

这是web.xml文件:


以下是JSP文件:

student.jsp


springmvc表单处理
学生信息
名称
年龄
身份证件

result.jsp:


springmvc表单处理
提交的学生信息
名称
${name}
年龄
${age}
身份证件
${id}

请帮我解决这个问题。

提前感谢。

在控制器中定义软件包捆绑包

package bundle;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
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;

将您的操作从student.jsp更改为

<form:form method="POST" action="addStudent">


它应该可以工作。

student.jsp中,将行更改为

<form:form method="POST" action="addStudent">


在OP的情况下,你的建议是有效的。请参阅OP在问题正文中讨论的教程链接。@user2083175那么原因是什么?使用
action=“addStudent”
而不是
action=“/HelloWeb/addStudent”
绝对不是原因。那是什么呢?使用action=“addstudent”是错误的一部分,student.jsp中addstudent的声明与我在student.jsp的caps中studentcontroller.java“S”中声明的不同,我在bean类中添加了ResourceViewResolver,因此它对我有效。
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
    <title>Spring MVC Form Handling</title>
</head>
<body>
    <h2>Student Information</h2>
    <form:form method="POST" action="/HelloWeb/addStudent">
        <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>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
    <title>Spring MVC Form Handling</title>
</head>
<body>
    <h2>Submitted Student 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>
package bundle;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
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;
<form:form method="POST" action="addStudent">
<form:form method="POST" action="addStudent">