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
Spring bean name';的BindingResult或普通目标对象;登记表';可用为请求属性错误_Spring_Spring Mvc_Servlets - Fatal编程技术网

Spring bean name';的BindingResult或普通目标对象;登记表';可用为请求属性错误

Spring bean name';的BindingResult或普通目标对象;登记表';可用为请求属性错误,spring,spring-mvc,servlets,Spring,Spring Mvc,Servlets,只是需要一个关于使用Spring的Spring表单功能的小帮助。我对Spring表单处理是新手。我创建了一个注册页面功能,在该功能中,用户只需输入其注册详细信息,并将其插入数据库。然而,在编写了所有设置代码之后,我得到了一个错误“BindingResult和bean名称的普通目标对象‘register_form’都不能作为请求属性使用”。我在这里检查了几个问题,并尝试了所有的方法。我发现我的代码是好的,但仍然得到这个错误 请查看我的以下文件: Web.xml: <?xml version=

只是需要一个关于使用Spring的Spring表单功能的小帮助。我对Spring表单处理是新手。我创建了一个注册页面功能,在该功能中,用户只需输入其注册详细信息,并将其插入数据库。然而,在编写了所有设置代码之后,我得到了一个错误“BindingResult和bean名称的普通目标对象‘register_form’都不能作为请求属性使用”。我在这里检查了几个问题,并尝试了所有的方法。我发现我的代码是好的,但仍然得到这个错误

请查看我的以下文件:

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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>TestFactoryPat</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>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/Application-context.xml, /WEB-INF/mvc-dispatcher-servlet.xml</param-value>
    </context-param>

   <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener>

   <servlet>
 <servlet-name>mvc-dispatcher</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <init-param>
  <param-name>contextConfigLocation</param-name>
 <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
 </servlet> 

 <servlet-mapping>
 <servlet-name>mvc-dispatcher</servlet-name>
 <url-pattern>/</url-pattern>
 </servlet-mapping>

</web-app>
Registeruser.jsp页面:

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@taglib uri="http://www.springframework.org/security/tags"
        prefix="sec"%>
    <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <!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>Test Registration</title>
        </head>

        <body>
            <h5> Registration Page</h5>

                <form:form id="RegisterForm" action="/submitRegistration" method="GET" modelAttribute="register_form">

<table>
                    <tr>
                        <td>FirstName</td>
                        <td>
                            <td>
                                <form:input path="register_form.firstName" size="30" />
                            </td>
                            <tr>
                                <td>LastName</td>
                                <td></td>
                            </tr>
                            <td>
                                <form:input path="register_form.LasttName" size="30" />
                            </td>
                            <tr>
                                <td>Email Address</td>
                                <td></td>
                            </tr>
                            <td>
                                <form:input path="register_form.EmailAddress" size="30" />
                            </td>
                            <tr>
                                <td>Address</td>
                                <td></td>
                            </tr>
                            <td>
                                <form:input path="register_form.Address" size="30" />
                            </td>
                            <tr>
                                <td>Phone</td>
                                <td></td>
                            </tr>
                            <td>
                                <form:input path="register_form.Phone" size="30" />
                            </td>
                            <tr>
                                <td>
                                    <input type="submit" value="Submit Registration">
                                </td>
                            </tr>
            </table>
            </form:form>
        </body>
    </html>

测试注册
注册页
名字
姓氏
电子邮件地址
住址
电话

请告诉我这个问题是否可以解决,我也检查了我所有的jar文件。

虽然它不能解决这个问题,但是你的表单提交方法应该是POST而不是GET

考虑到这一点,请对代码进行以下更改:

<form:form id = "RegisterForm" action = "/submitRegistration" method = "POST" commandName= "register_form">


@RequestMapping(value="/submitRegistration", method = RequestMethod.POST)
public String adduser(@ModelAttribute("register_form") Registration_info register_form)

@RequestMapping(value=“/submitRegistration”,method=RequestMethod.POST)
公共字符串adduser(@modeldattribute(“注册表表单”)注册表信息注册表表单)

与具体问题/异常无关:存在无效标记。你在
之前就开始了
,然后在
内部关闭了。我认为你提到的另一个问题是因为你在表单标签后面有
@Controller
public class RegisterController {

@Autowired
private BaseServices baseimpl;

    @RequestMapping(value="/submitRegistration", method = RequestMethod.GET)
    public String adduser(Registration_info register_form)  
    {
        baseimpl.saveorupdate(register_form);
        return null;    
    }
}
 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%@taglib uri="http://www.springframework.org/security/tags"
        prefix="sec"%>
    <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <!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>Test Registration</title>
        </head>

        <body>
            <h5> Registration Page</h5>

                <form:form id="RegisterForm" action="/submitRegistration" method="GET" modelAttribute="register_form">

<table>
                    <tr>
                        <td>FirstName</td>
                        <td>
                            <td>
                                <form:input path="register_form.firstName" size="30" />
                            </td>
                            <tr>
                                <td>LastName</td>
                                <td></td>
                            </tr>
                            <td>
                                <form:input path="register_form.LasttName" size="30" />
                            </td>
                            <tr>
                                <td>Email Address</td>
                                <td></td>
                            </tr>
                            <td>
                                <form:input path="register_form.EmailAddress" size="30" />
                            </td>
                            <tr>
                                <td>Address</td>
                                <td></td>
                            </tr>
                            <td>
                                <form:input path="register_form.Address" size="30" />
                            </td>
                            <tr>
                                <td>Phone</td>
                                <td></td>
                            </tr>
                            <td>
                                <form:input path="register_form.Phone" size="30" />
                            </td>
                            <tr>
                                <td>
                                    <input type="submit" value="Submit Registration">
                                </td>
                            </tr>
            </table>
            </form:form>
        </body>
    </html>
<form:form id = "RegisterForm" action = "/submitRegistration" method = "POST" commandName= "register_form">


@RequestMapping(value="/submitRegistration", method = RequestMethod.POST)
public String adduser(@ModelAttribute("register_form") Registration_info register_form)