java.lang.IllegalStateException:BindingResult和bean名称'versetmonth'的普通目标对象都不可用作请求属性

时间:2016-09-05 15:00:12

标签: java spring jsp tomcat

你好,我的jsp中有一个异常java.lang.IllegalStateException他说,无论是BindingResult还是bean名称'versetmonth'的普通目标对象都可用作请求属性。如果有人能帮助我,那将是友好的!

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'versetmonth' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
    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.TextareaTag.writeTagContent(TextareaTag.java:96)
    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.WEB_002dINF.views.versetmonth_jsp._jspx_meth_form_005ftextarea_005f0(versetmonth_jsp.java:561)
    at org.apache.jsp.WEB_002dINF.views.versetmonth_jsp._jspx_meth_form_005fform_005f0(versetmonth_jsp.java:503)
    at org.apache.jsp.WEB_002dINF.views.versetmonth_jsp._jspService(versetmonth_jsp.java:160)
    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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    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.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.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    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:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

sept. 05, 2016 4:47:15 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [webmvc-dispatcher] in context with path [/church] threw exception [An exception occurred processing JSP page /WEB-INF/views/versetmonth.jsp at line 46

43:               
44:                     <div class="col-md-4 col-sm-12">
45:                         <h5>Verset Anglais</h5>
46:                         <form:textarea path="texten" rows="12" class="form-control"/>
47:                     </div>
48:                     <div class="col-md-4 col-sm-12">
49:                         <h5>Verset Tamil</h5>


Stacktrace:] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'versetmonth' available as request attribute
    at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
    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.TextareaTag.writeTagContent(TextareaTag.java:96)
    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.WEB_002dINF.views.versetmonth_jsp._jspx_meth_form_005ftextarea_005f0(versetmonth_jsp.java:561)
    at org.apache.jsp.WEB_002dINF.views.versetmonth_jsp._jspx_meth_form_005fform_005f0(versetmonth_jsp.java:503)
    at org.apache.jsp.WEB_002dINF.views.versetmonth_jsp._jspService(versetmonth_jsp.java:160)
    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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    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.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.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1221)
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    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:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

这是我的jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
    <head>      

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="Home AGNC Church">
        <meta name="author" content="Carthy Marie joseph">
        <title>  <spring:message code="index.title.home"/>  </title>



        <!-- CSS -->
        <link href="<c:url value="/resources/userresource/css/edit.css" />" rel="stylesheet">
        <link href="<c:url value="/resources/userresource/css/bootstrap.min.css" />" rel="stylesheet">
        <!--<link href="<c:url value="/resources/userresource/css/font-awesome.min.css" />" rel="stylesheet">-->
        <link href="<c:url value="/resources/userresource/css/prettyPhoto.css" />" rel="stylesheet">
        <link href="<c:url value="/resources/userresource/css/animate.css" />" rel="stylesheet">
        <link href="<c:url value="/resources/userresource/css/main.css" />" rel="stylesheet">
        <!--[if lt IE 9]>
            <script src="<c:url value="/resources/js/html5shiv.js" />"></script>
            <script src="<c:url value="/resources/js/respond.min.js" />"></script>
        <![endif]-->
        <link rel="shortcut icon" href="<c:url value="/resources/images/ico/favicon.ico" />">

        <link rel="apple-touch-icon-precomposed" sizes="144x144" href="<c:url value="/resources/userresource/images/ico/apple-touch-icon-144-precomposed.png" />">
        <link rel="apple-touch-icon-precomposed" sizes="114x114" href="<c:url value="/resources/userresource/images/ico/apple-touch-icon-114-precomposed.png" />">
        <link rel="apple-touch-icon-precomposed" sizes="72x72" href="<c:url value="/resources/userresource/images/ico/apple-touch-icon-72-precomposed.png" />">
        <link rel="apple-touch-icon-precomposed" href="<c:url value="/resources/userresource/images/ico/apple-touch-icon-57-precomposed.png" />">


    </head>
    <body>
        <jsp:include page="navbar.jsp"/>
        <section class="container">
            <h3>Verset du mois</h3>
            <form:form action="versetmonth" modelAttribute="versetmonth" method="POST">
                <div class="row">

                    <div class="col-md-4 col-sm-12">
                        <h5>Verset Anglais</h5>
                        <form:textarea path="texten" rows="12" class="form-control"/>
                    </div>
                    <div class="col-md-4 col-sm-12">
                        <h5>Verset Tamil</h5>
                        <form:textarea path="textin" rows="12" class="form-control"/>
                    </div>
                    <div class="col-md-4 col-sm-12">
                        <h5>Verset Français</h5>
                        <form:textarea path="textfr" rows="12" class="form-control"/>
                    </div>
                </div>
                <div class="col-md-2 col-md-offset-5 col-sm-12">
                    <button class="btn btn-success btn-md btn-block">Submit</button>
                </div>
            </form:form>
    </section>


        <jsp:include page="footer.jsp"/>

        <script src="<c:url value="/resources/userresource/js/jquery.js" />"></script>

        <script src="<c:url value="/resources/userresource/js/bootstrap.min.js" />"></script>

        <script src="<c:url value="/resources/userresource/js/jquery.prettyPhoto.js" />"></script>

        <script src="<c:url value="/resources/userresource/js/main.js" />"></script>
    </body>
</html>

我的控制器

@Controller
@RequestMapping("/edit")
public class EditController {

    @RequestMapping(value = "/versetmonth", method = RequestMethod.GET)
    public String versetMonthGet(ModelMap model, HttpServletRequest request, HttpServletRequest response) {
        model.addAttribute("versetmonth", new VersetMonth());
        return "versetmonth";
    }

    @RequestMapping(value = "/versetmonth", method = RequestMethod.POST)
    public String versetMontPost(@Valid VersetMonth  versetmonth, BindingResult result, Model model,
            HttpServletRequest request, HttpServletRequest response) {
        if(result.hasErrors()) {
            return "versetmonth";
        }
        return "versetmonth";
    }


}

和我的模特

@Entity
@Table(name = "VERSETMONTH")
public class VersetMonth {
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int userId;

    @NotNull
    @Column(name = "TEXTEN")
    private String texten;

    @NotNull
    @Column(name = "TEXTIN")
    private String textin;

    @NotNull
    @Column(name = "TEXTFR")
    private String textfr;

    public String getTexten() {
        return texten;
    }

    public void setTexten(String texten) {
        this.texten = texten;
    }

    public String getTextin() {
        return textin;
    }

    public void setTextin(String textin) {
        this.textin = textin;
    }

    public String getTextfr() {
        return textfr;
    }

    public void setTextfr(String textfr) {
        this.textfr = textfr;
    }


}

感谢您的回答!!!

1 个答案:

答案 0 :(得分:0)

在post方法中你需要再次传递modelAttribute,即

@RequestMapping(value = "/versetmonth", method = RequestMethod.POST)
    public String versetMontPost(@Valid VersetMonth  versetmonth, BindingResult result, Model model,
            HttpServletRequest request, HttpServletRequest response) {
        model.addAttribute("versetmonth", versetmonth);
        if(result.hasErrors()) {  
            return "versetmonth";
        }
        return "versetmonth";
    }