Results 1 to 8 of 8
  1. #1
    Chetans is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default java.lang.IllegalStateException:Neither BindingResult nor plain target object 4 bean

    I am a newbie at Spring 3.1 MVC, and I need some help. I must be missing something, but I can't figure out what.
    It is giving java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'updateUser' available as request attribute after login action called.

    Here is my Dispatcher-servlet.xml
    XML Code:
       <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
        <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
    
        <!--
        Most controllers will use the ControllerClassNameHandlerMapping above, but
        for the index controller we are using ParameterizableViewController, so we must
        define an explicit mapping for it.
        -->
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
        p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
        
        <bean name="/login.htm" class="Model.Login" p:formView="LoginForm" p:successView="welcome"/>
        <bean name="/register.htm" class="Model.Register" p:formView="Register" p:successView="welcome"/>
        <bean name="/updateUser.htm" class="Model.UpdateUser" p:formView="welcome" p:successView="unsuccess" />
    
    </beans>
    LoginForm.jsp

    XML Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
             pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="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>Login</title>
        </head>
        <body>  
            <h1>Login Here!</h1>
            <form:form method="POST" commandName="login" id="login">
                <table>
                    <tbody>
                        <tr>
                            <td>Login ID :</td>
                            <td><form:input path="loginID"/></td>
                        </tr>
                        <tr>
                            <td>Password :</td>
                            <td><form:password path="password"/></td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <input type="submit" name="submit" value="Login"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <a href="register.htm">Not Registered ???</a>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <span style="color: red">${login.errorMessage}</span>
            </form:form>  
    </body>
    </html>
    Welcome.jsp

    XML Code:
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Welcome</title>
            <script type="text/javascript">
                function showDetails(id){
                    document.getElementById("nameA").value=document.getElementById("name"+id).value;
                    document.getElementById("loginIDA").value=document.getElementById("loginID"+id).value;
                }
            </script>
        </head>
        <body>
            <h1>Login Successful!</h1>
            <span style="color: green">Welcome ${login.loginID}</span><br/>
            Registered users are :<br/>
            <table border="1" cellspacing="0" width="50%">
                <thead style="background-color:lightskyblue">
                    <tr>
                        <th>Sr.No.</th>
                        <th>Name</th>
                        <th>User ID</th>
                        <th>Password</th>
                    </tr>
                </thead>
                <tbody>
                    <% int i = 1;%>
                    <c:forEach var="o" items="${login.registeredUsers}">
                        <tr align="center">
                            <td><%=i%></td>
                            <td><a href="#" onclick="showDetails(<%=i%>)" style="text-decoration: none;color:#006666;">${o.name}</a></td>
                            <td>${o.loginID}</td>
                            <td>${o.password}</td>
                        </tr>
                        <tr style="display: none">
                            <td></td>
                            <td><input type="hidden" id="name<%=i%>" value="${o.name}"/></td>
                            <td><input type="hidden" id="loginID<%=i%>" value="${o.loginID}"/></td>
                            <td><input type="hidden" id="password<%=i%>" value="${o.password}"/></td>
                        </tr>
                        <% i++;%>
                    </c:forEach>
                </tbody>
            </table>
            <br/><hr/><br/> 
            <form:form method="POST" commandName="updateUser">
                <table>
                    <tbody>
                        <tr style="background-color:#660066">
                            <td style="color: white">User ID :</td>
                            <td>
                                <form:input path="loginID"/>
                            </td>
                        </tr>
                        <tr>
                            <td>Name :</td>
                            <td><form:input path="name"/></td>
                        </tr>
                        <tr>
                            <td>Password :</td>
                            <td><form:input path="password"/></td>
                        </tr>
                        <tr>
                            <td>Confirm Password :</td>
                            <td><form:input path="confirmPassword"/></td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <hr/>
                                <input type="submit" name="update" value="Update"/>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form:form>  
    </body>
    </html>
    Login.java extends SimpleFormController

    Java Code:
        public Login() {
            setCommandClass(LoginBean.class);
            setCommandName("login");
        }
    
        @Override
        protected ModelAndView onSubmit(Object command) throws Exception {
            LoginBean loginBean = (LoginBean) command;
            ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
    
            LoginJDBCTemplate loginJDBCTemplate = (LoginJDBCTemplate) context.getBean("loginJDBCTemplate");
    
            if (loginJDBCTemplate.authenticateUser(loginBean.getLoginID(), loginBean.getPassword())) {
                loginBean.setRegisteredUsers(loginJDBCTemplate.listUsers());
                return new ModelAndView("welcome", "login", loginBean);
            } else {
                loginBean.setErrorMessage("User ID or Password incorrect !!!!");
                return new ModelAndView("LoginForm", "login", loginBean);
            }
        }
    UpdateUser.java extends SimpleFormController
    Java Code:
        public UpdateUser() {
            setCommandClass(UpdateUserBean.class);
            setCommandName("updateUser");
        }
        @Override
        protected ModelAndView onSubmit(Object command) throws Exception {
            UpdateUserBean updateUserBean = (UpdateUserBean) command;
            ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
    
            LoginJDBCTemplate loginJDBCTemplate = (LoginJDBCTemplate) context.getBean("loginJDBCTemplate");
    
            return new ModelAndView("welcome", "updateUser", updateUserBean);
        }
    LoginBean.java
    Java Code:
        private String loginID;
        private String password;
        private String confirmPassword;
        private String errorMessage;
        private String name;
        private List registeredUsers = new ArrayList();
    
        public List getRegisteredUsers() {
            return registeredUsers;
        }
    
        public void setRegisteredUsers(List registeredUsers) {
            this.registeredUsers = registeredUsers;
        }
    
        public String getConfirmPassword() {
            return confirmPassword;
        }
    
        public void setConfirmPassword(String confirmPassword) {
            this.confirmPassword = confirmPassword;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getErrorMessage() {
            return errorMessage;
        }
    
        public void setErrorMessage(String errorMessage) {
            this.errorMessage = errorMessage;
        }
    
        public String getLoginID() {
            return loginID;
        }
    
        public void setLoginID(String loginID) {
            this.loginID = loginID;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        public LoginBean(String loginID, String password, String confirmPassword, String errorMessage, String name) {
            this.loginID = loginID;
            this.password = password;
            this.confirmPassword = confirmPassword;
            this.errorMessage = errorMessage;
            this.name = name;
        }
    
        public LoginBean(String loginID, String password, String errorMessage) {
            this.loginID = loginID;
            this.password = password;
            this.errorMessage = errorMessage;
        }
    
        public LoginBean() {
        }
    UpdateUserBean.java
    Java Code:
        private String loginID;
        private String password;
        private String confirmPassword;
        private String errorMessage;
        private String name;
        public String getConfirmPassword() {
            return confirmPassword;
        }
    
        public void setConfirmPassword(String confirmPassword) {
            this.confirmPassword = confirmPassword;
        }
    
        public String getErrorMessage() {
            return errorMessage;
        }
    
        public void setErrorMessage(String errorMessage) {
            this.errorMessage = errorMessage;
        }
    
        public String getLoginID() {
            return loginID;
        }
    
        public void setLoginID(String loginID) {
            this.loginID = loginID;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
        public UpdateUserBean() {
        }
    
        public UpdateUserBean(String loginID, String password, String confirmPassword, String errorMessage, String name) {
            this.loginID = loginID;
            this.password = password;
            this.confirmPassword = confirmPassword;
            this.errorMessage = errorMessage;
            this.name = name;
        }
    Beans.xml
    XML Code:
        <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
       
        <bean id="dataSource"
              class="org.springframework.jdbc.datasource.DriverManagerDataSource"
              p:driverClassName="com.mysql.jdbc.Driver"
              p:url="jdbc:mysql://localhost:3306/TEST"
              p:username="root"
              p:password="exitosys" />
    
        <bean id="studentJDBCTemplate" class="DatabaseExample.StudentJDBCTemplate">
            <property name="dataSource"  ref="dataSource" />    
        </bean>
        <bean id="loginJDBCTemplate" class="Model.LoginJDBCTemplate">
            <property name="dataSource"  ref="dataSource" />    
        </bean>
        <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
    
    </beans>
    Last edited by Chetans; 09-25-2012 at 12:30 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: java.lang.IllegalStateException:Neither BindingResult nor plain target object 4 b

    When is this being thrown?
    What is the full stack trace?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: java.lang.IllegalStateException:Neither BindingResult nor plain target object 4 b

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Chetans is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Arrow Re: java.lang.IllegalStateException:Neither BindingResult nor plain target object 4 b

    Quote Originally Posted by Tolls View Post
    When is this being thrown?
    What is the full stack trace?
    HTTP Status 500 -

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/welcome.jsp at line 63

    60: <td style="color: white">User ID :</td>
    61: <td>
    62:
    63: <form:input path="loginID"/>
    64: </td>
    65: </tr>
    66: <tr>


    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:567)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:466)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:389)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)
    org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:238)
    org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1047)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:817)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:669)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:585)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)

    root cause

    java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'updateUser' available as request attribute
    org.springframework.web.servlet.support.BindStatus .<init>(BindStatus.java:141)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getBindStatus(AbstractData BoundFormElementTag.java:174)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getPropertyPath(AbstractDa taBoundFormElementTag.java:194)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.getName(AbstractDataBoundF ormElementTag.java:160)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.autogenerateId(AbstractDat aBoundFormElementTag.java:147)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.resolveId(AbstractDataBoun dFormElementTag.java:138)
    org.springframework.web.servlet.tags.form.Abstract DataBoundFormElementTag.writeDefaultAttributes(Abs tractDataBoundFormElementTag.java:122)
    org.springframework.web.servlet.tags.form.Abstract HtmlElementTag.writeDefaultAttributes(AbstractHtml ElementTag.java:408)
    org.springframework.web.servlet.tags.form.InputTag .writeTagContent(InputTag.java:140)
    org.springframework.web.servlet.tags.form.Abstract FormTag.doStartTagInternal(AbstractFormTag.java:10 2)
    org.springframework.web.servlet.tags.RequestContex tAwareTag.doStartTag(RequestContextAwareTag.java:7 9)
    org.apache.jsp.WEB_002dINF.jsp.welcome_jsp._jspx_m eth_form_005finput_005f0(welcome_jsp.java:281)
    org.apache.jsp.WEB_002dINF.jsp.welcome_jsp._jspx_m eth_form_005fform_005f0(welcome_jsp.java:224)
    org.apache.jsp.WEB_002dINF.jsp.welcome_jsp._jspSer vice(welcome_jsp.java:182)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:433)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:389)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)
    org.springframework.web.servlet.view.InternalResou rceView.renderMergedOutputModel(InternalResourceVi ew.java:238)
    org.springframework.web.servlet.view.AbstractView. render(AbstractView.java:250)
    org.springframework.web.servlet.DispatcherServlet. render(DispatcherServlet.java:1047)
    org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:817)
    org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
    org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:669)
    org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:585)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
    org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:393)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.22 logs.

    Apache Tomcat/7.0.22
    Last edited by Chetans; 09-25-2012 at 10:47 AM.

  5. #5
    Chetans is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default Re: java.lang.IllegalStateException:Neither BindingResult nor plain target object 4 b

    Thanks for the help Darryl Burke !!!
    Last edited by Chetans; 09-25-2012 at 12:25 PM.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: java.lang.IllegalStateException:Neither BindingResult nor plain target object 4 b

    Took me a while since you never did read Darryl's link and add [code] tags [/code].
    I very nearly didn't bother since I find it almost impossible to read unformatted code.

    Java Code:
    return new ModelAndView("welcome", "login", loginBean);
    That is from your Login action.

    Java Code:
    <form:form method="POST" commandName="updateUser">
    that is the page it is forwarding to (Welcome.jsp).

    Your command is different.
    In the first you are giving it a "login", in the second you are saying "updateUser".
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Chetans is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default Re: java.lang.IllegalStateException:Neither BindingResult nor plain target object 4 b

    Ok Thanx Tolls...
    And very sorry for unformatted code. I have formatted it just now.

    I want to call UpdateUser.java to update the specific record. So how can i do that?

  8. #8
    Chetans is offline Member
    Join Date
    Feb 2010
    Posts
    15
    Rep Power
    0

    Default Re: java.lang.IllegalStateException:Neither BindingResult nor plain target object 4 b

    Quote Originally Posted by Tolls View Post
    Took me a while since you never did read Darryl's link and add [code] tags [/code].
    I very nearly didn't bother since I find it almost impossible to read unformatted code.

    Java Code:
    return new ModelAndView("welcome", "login", loginBean);
    That is from your Login action.

    Java Code:
    <form:form method="POST" commandName="updateUser">
    that is the page it is forwarding to (Welcome.jsp).

    Your command is different.
    In the first you are giving it a "login", in the second you are saying "updateUser".
    Ok Thanx Tolls...
    And very sorry for unformatted code. I have formatted it just now.

    I want to call UpdateUser.java to update the specific record. So how can i do that?

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 02:12 AM
  2. Replies: 12
    Last Post: 09-17-2010, 12:40 AM
  3. GUI with java.lang.IllegalStateException
    By eckt in forum AWT / Swing
    Replies: 4
    Last Post: 06-14-2010, 10:32 AM
  4. Replies: 2
    Last Post: 12-14-2009, 01:46 AM
  5. Replies: 13
    Last Post: 09-07-2009, 04:32 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •