当前位置: 首页 > 知识库问答 >
问题:

java.lang.IllegalStateException-bean名称既不是BindingResult也不是普通目标对象

邹英发
2023-03-14

我正在开发一个控制器来控制系统上的寄存器。这是我的控制器代码:

@Controller
@RequestMapping("/consumer")
public class ConsumerController extends AbstractController {
    public ConsumerController() {
        super();
    }

    //Services
    @Autowired
    ConsumerService consumerService;
    //Constructors


    // Lista de consumidores ---------------------------------------------------------------        
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public ModelAndView listConsumers() {
        ModelAndView result = new ModelAndView("consumer/list");
        Collection<Consumer> consumers = consumerService.getAllConsumer();
        result.addObject("customers",consumers);
        result.addObject("customerType", "Consumer");
        result.addObject("requestURI","consumer/list.do");
        return result;
    }

    //Registrar como consumidor

    @RequestMapping(value="/register", method  = RequestMethod.GET)
    public ModelAndView create(){
        ModelAndView result;
        Consumer consumer = consumerService.create();
        result = createEditModelAndView(consumer);
        return result;
    }
    protected ModelAndView createEditModelAndView(Consumer consumer){
        ModelAndView result = createEditModelAndView(consumer, null);
        return result;
    }

    protected ModelAndView createEditModelAndView(Consumer consumer, String message){

        ModelAndView result;
        result = new ModelAndView("consumer/register");
        result.addObject("authority", consumer);
        result.addObject("message",message);
        return result;
    }

}

这是我的观点:

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@taglib prefix="jstl" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="security" uri="http://www.springframework.org/security/tags"%>
<%@taglib prefix="display" uri="http://displaytag.sf.net"%>

<form:form action="consumer/save.do"  modelAttribute="${authority }">
<form:hidden path="id"/>
    <form:hidden path="version"/>
    <form:hidden path="ticker"/>

    <form:label path="username">
        <spring:message code="register.customer.username" />
    </form:label>
    <form:input path="username"/>
    <form:errors cssClass="error" path="username"/>
    <br />

    <form:label path="password">
    <spring:message code="register.customer.password" />
    </form:label>
    <form:password path="password"/>
    <form:errors cssClass="error" path="password"/>
    <br />

    <form:label path="confirmpassword">
    <spring:message code="register.customer.confirmpassword" />
    </form:label>
    <form:password path="confirmpassword"/>
    <form:errors cssClass="error" path="confirmpassword"/>
    <br />

    <form:label path="name">
    <spring:message code="register.customer.name" />
    </form:label>
    <form:input path="name"/>
    <form:errors cssClass="error" path="name"/>
    <br />

    <form:label path="surname">
    <spring:message code="register.customer.surname" />
    </form:label>
    <form:input path="surname"/>
    <form:errors cssClass="error" path="surname"/>
    <br />

    <form:label path="email">
    <spring:message code="register.customer.email" />
    </form:label>
    <form:input path="email"/>
    <form:errors cssClass="error" path="email"/>
    <br />

    <form:label path="holdername">
    <spring:message code="register.customer.holdername" />
    </form:label>
    <form:input path="holdername"/>
    <form:errors cssClass="error" path="holdername"/>
    <br />

    <form:label path="brandname">
    <spring:message code="register.customer.brandname" />
    </form:label>
    <form:input path="brandname"/>
    <form:errors cssClass="error" path="brandname"/>
    <br />

    <form:label path="number">
    <spring:message code="register.customer.number" />
    </form:label>
    <form:input path="number"/>
    <form:errors cssClass="error" path="number"/>
    <br />

    <form:label path="expirationyear">
    <spring:message code="register.customer.expirationyear" />
    </form:label>
    <form:input path="expirationyear"/>
    <form:errors cssClass="error" path="expirationyear"/>
    <br />

    <form:label path="expirationmonth">
    <spring:message code="register.customer.expirationmonth" />
    </form:label>
    <form:input path="expirationmonth"/>
    <form:errors cssClass="error" path="expirationmonth"/>
    <br />

    <form:label path="cvv">
    <spring:message code="register.customer.cvv" />
    </form:label>
    <form:input path="cvv"/>
    <form:errors cssClass="error" path="cvv"/>
    <br />

    <form:label path="terms">
    <spring:message code="register.customer.terms" />
    </form:label>
    <form:checkbox path="terms"/>
    <form:errors cssClass="error" path="terms"/>
    <br />

    <input type="submit" name="save" value="<spring:message code="register.customer.save"/>" />
    &nbsp;
    <input type="button" name="cancel" value="<spring:message code="register.customer.cancel"/>" 
    onclick="javascript: window.location.replace('')"/>

</form:form>

这是我的tiles.xml:

<tiles-definitions>

    <definition name="consumer/list" extends="master.page"> 
        <put-attribute name="title" value="List of consumers" />
        <put-attribute name="body" value="/views/customer/list.jsp" />
    </definition>

    <definition name="supplier/list" extends="master.page"> 
        <put-attribute name="title" value="List of suppliers" />
        <put-attribute name="body" value="/views/customer/list.jsp" />
    </definition>

    <definition name="consumer/register" extends="master.page"> 
        <put-attribute name="title" value="Register" />
        <put-attribute name="body" value="/views/customer/register.jsp" />
    </definition>   

    <definition name="supplier/register" extends="master.page"> 
        <put-attribute name="title" value="Register" />
        <put-attribute name="body" value="/views/customer/register.jsp" />
    </definition>   


</tiles-definitions>
Dec 10, 2014 4:29:52 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Acme-BrokerServlet] in context with path [/Acme-Broker] threw exception [Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException: ServletException including path '/views/master-page/layout.jsp'.] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'consumer' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:141)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:141)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:132)
    at org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:116)
    at org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422)
    at org.springframework.web.servlet.tags.form.HiddenInputTag.writeTagContent(HiddenInputTag.java:79)
    at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
    at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
    at org.apache.jsp.views.customer.register_jsp._jspx_meth_form_005fhidden_005f0(register_jsp.java:647)
    at org.apache.jsp.views.customer.register_jsp._jspService(register_jsp.java:113)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
    at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)
    at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)
    at org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)
    at org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)
    at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
    at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
    at org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer.write(ChainedDelegateAttributeRenderer.java:76)
    at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)
    at org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)
    at org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)
    at org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)
    at org.apache.jsp.views.master_002dpage.layout_jsp._jspx_meth_tiles_005finsertAttribute_005f3(layout_jsp.java:228)
    at org.apache.jsp.views.master_002dpage.layout_jsp._jspService(layout_jsp.java:141)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
    at org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)
    at org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)
    at org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)
    at org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)
    at org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:88)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:266)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

我会继续努力解决这个问题,谢谢你的关注!

共有1个答案

公冶元青
2023-03-14

尝试:

<form:form action="consumer/save.do"  modelAttribute="authority">

参见:

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/spring-form.tld.html#spring-form.tld.form

 类似资料:
  • 问题内容: 由于某些原因,即使在这里查看了多个示例之后,我似乎也无法解决此问题。 我正在尝试使用Spring 3 MVC处理表单,但是出现以下错误: 因此,我有点想解决这里的问题,但未能解决。这是我的方法 ReverseController类扩展了SimpleFormController: 我的app-servlet.xml定义控制器如下: 这是我的reverse.jsp中的形式: 这就是我的we

  • carview.jsp ApplicationContext.xml web.xml 错误 grave:加载应用程序时出现异常grave:上下文/MyCar取消部署失败grave:加载应用程序时出现异常:java.lang.IllegalStateException:ContainerBase.AddChild:Start:org.apache.catalina.LifecycleExceptio

  • 在我的基本spring mvc应用程序中,我遇到了一个例外。我使用的是。我的代码如下。 在我的调度器-servlet中 在我的JSP页面中 在我的控制器课上 一旦用户输入正确的用户名和密码,就会重定向到页面。这工作正常。但是用户输入了错误的登录凭据,这会引发此错误。 例外 组织。springframework。网状物util。NestedServletException:请求处理失败;嵌套的例外是

  • 是的,我读到这是一个很常见的问题,但是阅读这些帖子并没有真正帮助我。 小故事是我想在showAllComments.jsp上提交一个表单 以下是控制器: 结果如下:Java . lang . illegalstateexception:bean名称“command”的BindingResult和plain target对象都不能作为请求属性 但您可能需要从一开始就了解整个故事:用户在索引上启动应用

  • 这是一个广泛的经典问题 我正在尝试编写一个Spring MVC web应用程序,用户可以在其中向内存中的集合添加电影名称。它是这样配置的 和 软件包

  • 我试图在Tomcat 8.0服务器上使用Spring框架开发一个网络应用程序,但是,我被这个错误卡住了。其他两个表单页能够通过使用ModelAtinn绑定表单中的数据,然而,第三个userprofile.jsp是抛出错误“BindingResult或bean名称'setupuser'的普通目标对象都不可用作请求属性”。请帮我改掉这个错误。谢啦 错误- 可选服务控制器。爪哇- 用户配置文件。jsp