Java 错误:bean名称“XXX”的BindingResult或普通目标对象都不能作为请求属性使用

Java 错误:bean名称“XXX”的BindingResult或普通目标对象都不能作为请求属性使用,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,我得到了这个错误,我确信我已经匹配了相同的名字。 请帮帮我 bean名称“userForm”的BindingResult和普通目标对象都不能作为请求属性使用 这是index.jsp <%@ include file="/WEB-INF/jsp/taglibs.jsp" %> <div class="row"> <div class="panel panel-default"> <div class="panel-body"&g

我得到了这个错误,我确信我已经匹配了相同的名字。 请帮帮我

bean名称“userForm”的BindingResult和普通目标对象都不能作为请求属性使用

这是index.jsp

<%@ include file="/WEB-INF/jsp/taglibs.jsp" %>


<div class="row">
    <div class="panel panel-default">
        <div class="panel-body">

            <form:form  action="dummy" method="post" commandName="userForm">

                <table border="0">
                <tr>
                    <td colspan="2" align="center"><h2>Spring MVC Form Demo - Registration</h2></td>
                </tr>
                <tr>
                    <td>User Name:</td>
                    <td>
                    <form:input path="username" />
                    </td>
                </tr>
                <tr>
                    <td>Profession:</td>
                    <td><form:select path="profession" items="${professionList}" /></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><input type="submit" value="Register" /></td>
                </tr>
                </table>
                </form:form>

            </form>
</div>
</div>
</div>
registrationSuccess.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>

</body><%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>   
<!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=UTF-8">
<title>Registration Success</title>
</head>
<body>
    <div align="center">
        <table border="0">
            <tr>
                <td colspan="2" align="center"><h2>Registration Succeeded!</h2></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <h3>Thank you for registering! Here's the review of your details:</h3>
                </td>
            </tr>
            <tr>
                <td>User Name:</td>
                <td>${userForm.username}</td>
            </tr>

            <tr>
                <td>Profession:</td>
                <td>${userForm.profession}</td>
            </tr>

        </table>
    </div>
</body>
</html>
</html>

您的jsp称为registrationSuccess,但您的请求映射为dummy.html。请尝试将请求映射更改为registrationSuccess您试图点击的URL是什么?您是点击控制器url还是直接点击JSP url?
public class User {

    private String username;
    private String profession;

    public User() {

        // TODO Auto-generated constructor stub
    }

    public User(String username, String profession) {

        this.username = username;
        this.profession = profession;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getProfession() {
        return profession;
    }

    public void setProfession(String profession) {
        this.profession = profession;
    }

}
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>

</body><%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>   
<!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=UTF-8">
<title>Registration Success</title>
</head>
<body>
    <div align="center">
        <table border="0">
            <tr>
                <td colspan="2" align="center"><h2>Registration Succeeded!</h2></td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <h3>Thank you for registering! Here's the review of your details:</h3>
                </td>
            </tr>
            <tr>
                <td>User Name:</td>
                <td>${userForm.username}</td>
            </tr>

            <tr>
                <td>Profession:</td>
                <td>${userForm.profession}</td>
            </tr>

        </table>
    </div>
</body>
</html>
</html>