java - Neither Binding result nor plain target for bean name user available as request attribute -
i new spring , hibernate. when try open jsp page getting following error:
severe: neither bindingresult nor plain target object bean name 'user' available request attribute java.lang.illegalstateexception: neither bindingresult nor plain target object bean name 'user' available request attribute @ org.springframework.web.servlet.support.bindstatus.<init>(bindstatus.java:144) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getbindstatus(abstractdataboundformelementtag.java:168) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getpropertypath(abstractdataboundformelementtag.java:188) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getname(abstractdataboundformelementtag.java:154) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.autogenerateid(abstractdataboundformelementtag.java:141) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.resolveid(abstractdataboundformelementtag.java:132) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.writedefaultattributes(abstractdataboundformelementtag.java:116) @ org.springframework.web.servlet.tags.form.abstracthtmlelementtag.writedefaultattributes(abstracthtmlelementtag.java:422) @ org.springframework.web.servlet.tags.form.inputtag.writetagcontent(inputtag.java:142) @ org.springframework.web.servlet.tags.form.abstractformtag.dostarttaginternal(abstractformtag.java:84) @ org.springframework.web.servlet.tags.requestcontextawaretag.dostarttag(requestcontextawaretag.java:80) @ org.apache.jsp.views.registeruser_jsp._jspx_meth_form_005finput_005f0(registeruser_jsp.java:177) @ org.apache.jsp.views.registeruser_jsp._jspservice(registeruser_jsp.java:97) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:731) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:439) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:395) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:339) @ javax.servlet.http.httpservlet.service(httpservlet.java:731) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:505) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:957) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:423) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1079) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:620) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:318) @ java.util.concurrent.threadpoolexecutor$worker.runtask(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source) 25 jun, 2015 5:54:22 org.apache.catalina.core.standardwrappervalve invoke severe: servlet.service() servlet [jsp] in context path [/banking] threw exception [java.lang.illegalstateexception: neither bindingresult nor plain target object bean name 'user' available request attribute] root cause java.lang.illegalstateexception: neither bindingresult nor plain target object bean name 'user' available request attribute @ org.springframework.web.servlet.support.bindstatus.<init>(bindstatus.java:144) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getbindstatus(abstractdataboundformelementtag.java:168) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getpropertypath(abstractdataboundformelementtag.java:188) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.getname(abstractdataboundformelementtag.java:154) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.autogenerateid(abstractdataboundformelementtag.java:141) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.resolveid(abstractdataboundformelementtag.java:132) @ org.springframework.web.servlet.tags.form.abstractdataboundformelementtag.writedefaultattributes(abstractdataboundformelementtag.java:116) @ org.springframework.web.servlet.tags.form.abstracthtmlelementtag.writedefaultattributes(abstracthtmlelementtag.java:422) @ org.springframework.web.servlet.tags.form.inputtag.writetagcontent(inputtag.java:142) @ org.springframework.web.servlet.tags.form.abstractformtag.dostarttaginternal(abstractformtag.java:84) @ org.springframework.web.servlet.tags.requestcontextawaretag.dostarttag(requestcontextawaretag.java:80) @ org.apache.jsp.views.registeruser_jsp._jspx_meth_form_005finput_005f0(registeruser_jsp.java:177) @ org.apache.jsp.views.registeruser_jsp._jspservice(registeruser_jsp.java:97) @ org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) @ javax.servlet.http.httpservlet.service(httpservlet.java:731) @ org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:439) @ org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:395) @ org.apache.jasper.servlet.jspservlet.service(jspservlet.java:339) @ javax.servlet.http.httpservlet.service(httpservlet.java:731) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:505) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:957) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:423) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1079) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:620) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:318) @ java.util.concurrent.threadpoolexecutor$worker.runtask(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(unknown source)
here code:
registeruser.jsp
<%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <%@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/core" prefix="c"%> <!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>register user</title> </head> <body> <form:form commandname="user"> <table> <tr> <td>user name</td> <td><form:input path="username"/></td> </tr> <tr> <td>password</td> <td><form:input path="password"/></td> </tr> <tr> <td></td> <td> <input type="submit" id="submitbtn" value="post"/> </td> </tr> </table> <p > <% if(request.getattribute("errormessage") != null) { out.println(request.getattribute("errormessage")); } %> </p> </form:form> </body> </html>
usercontroller.java
package com.krishnaja.controller; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.validation.bindingresult; import org.springframework.web.bind.annotation.modelattribute; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import com.krishnaja.entity.user; import com.krishnaja.service.userservice; @controller public class usercontroller { @autowired private userservice userservice; public usercontroller(){} @requestmapping(value = "/", method = requestmethod.post) public string saveuser(@modelattribute("user")user user, bindingresult result) { userservice.saveuser(user); return "redirect:/index.jsp"; } }
userserviceimpl.java
package com.krishnaja.service; import java.util.list; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.service; import org.springframework.transaction.annotation.transactional; import com.krishnaja.dao.userdao; import com.krishnaja.entity.user; @service public class userserviceimpl implements userservice { @autowired private userdao userdao; @transactional public void saveuser(user user) { userdao.saveuser(user); } @transactional public list<user> retrieveallusers() { return userdao.retrieveallusers(); } }
spring-servlet.xml
<?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:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:flex="http://www.springframework.org/schema/flex" xmlns:amq="http://activemq.apache.org/schema/core" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd http://www.springframework.org/schema/flex http://www.springframework.org/schema/flex/spring-flex-1.0.xsd" > <context:annotation-config /> <context:component-scan base-package="com.krishnaja.controller"/> <context:component-scan base-package="com.krishnaja.dao"/> <context:component-scan base-package="com.krishnaja.service"/> <context:component-scan base-package="com.krishnaja.entity"/> <bean id="user" class="com.krishnaja.controller.usercontroller"></bean> <bean id="jspviewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="viewclass" value="org.springframework.web.servlet.view.jstlview" /> <property name="prefix" value="/web-inf/views/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="messagesource" class="org.springframework.context.support.reloadableresourcebundlemessagesource"> <property name="basename" value="resources/user.properties" /> <property name="defaultencoding" value="utf-8" /> </bean> <bean id="propertyconfigurer" class="org.springframework.beans.factory.config.propertyplaceholderconfigurer" p:location="/web-inf/jdbc.properties" /> <bean id="datasource" class="org.apache.commons.dbcp.basicdatasource" destroy-method="close" p:driverclassname="${jdbc.driverclassname}" p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" /> <bean id="sessionfactory" class="org.springframework.orm.hibernate4.localsessionfactorybean"> <property name="datasource" ref="datasource" /> <property name="configlocation"> <value>/web-inf/hibernate.cfg.xml</value> </property> <property name="hibernateproperties"> <props> <prop key="hibernate.dialect">${jdbc.dialect}</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <tx:annotation-driven /> <bean id="transactionmanager" class="org.springframework.orm.hibernate3.hibernatetransactionmanager"> <property name="sessionfactory" ref="sessionfactory" /> </bean> </beans>
you getting exception because haven't add model object that's why exception has been thrown.
try add in controller
model.addobject("user", user);
and in jsp page
<form:form commandname="user" modelattribute="user">
i hope you
Comments
Post a Comment