spring - HTTP Status 500 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'app' available as request attribute -
i getting eror in spring mvc 3.2 + jdbc project.
"http status 500 - java.lang.illegalstateexception: neither bindingresult nor plain target object bean name 'app' available request attribute"
i have seen people asked question. have gone through answers . nbothing s working me. please me . in advance.
this homecontroller.java:-
import java.util.arraylist; import org.springframework.beans.factory.annotation.autowired; import org.springframework.stereotype.controller; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.modelandview; import mediatoprima.beans.application; import mediatoprima.services.applicationservice; import java.util.hashmap; import java.util.list; import java.util.map; @controller public class mediatoprimacontroller { @autowired applicationservice applicationservice; @requestmapping("/appmgt_addnewapp") public modelandview registeruser(@modelattribute("application") application app) { list<string> loblist = new arraylist<string>(); loblist.add("asia"); loblist.add("australia"); loblist.add("america"); loblist.add("europe"); map<string, list> map = new hashmap<string, list>(); map.put("citylist", loblist); return new modelandview("appmgt_addnewapp", "map", map); } @requestmapping("/insert") public string inserdata(@modelattribute application application) { if (application != null) applicationservice.addnewapp(application); return "redirect:/appmanagment"; } }
this apmgt_addnewapp.jsp welcome file of prijct
<%@ 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> <script type="text/javascript" src="css/appmang.js"></script> <link rel="stylesheet" type="text/css" href="styles.css"> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>:: new application < title> </head> <body> <div id="content_page_for_userhome"><br> <div id="divforsidenavigation"> <center> <ul> <li><a href="appmgt_addnewapp.html"><img src="images/add.png" border="0" /><br> new application</a></li> </ul> </center> </div> <div id="addnewbox_app"><form:form action="addnewapp" method="post" modelattribute="application"> <center><c:url var="action" value="/appmgt_addnewapp.html"></c:url> <form:form method="post" action="/insert" modelattribute="app"> <table> <tr align="left"> <td>appid</td> <td><form:input path="id" readonly="true" size="8" disabled="true" id="txt"/> <form:hidden path="id" /></td> <td>*</td> </tr> <tr align="left"> <td>appcode</td> <td><form:input path="appcode" /></td> <td>*</td> </tr> <tr align="left"> <td>application</td> <td><form:input path="appname" /></td> <td>*</td> </tr> <tr align="left"> <td>lob</td> <td><form:input path="lob" /></td> <td>*</td> </tr> <tr align="left"> <td>geog</td> <td><form:input path="geo" /></td> <td>*</td> </tr> <tr align="left"> <td>desc</td> <td><form:input path="desc" /></td> </tr> <tr align="left"> <td colspan="2" align="center"><input type="submit" value="save" class="appbutton"/> <input type="button" value="cancel" class="appbutton" /></td> </tr> </table> </form:form></center> </form:form></div> </div> </body> </html>
this spring-servlet.xml file
<?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" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <!-- telling container take care of annotations stuff --> <context:annotation-config /> <!-- declaring base package --> <context:component-scan base-package="com" /> <!-- adding view resolver show jsp's on browser --> <bean id="viewresolver" class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <!-- declare beans --> <bean id="applicationdao" class="com.dao.applicationdaoimpl" /> <bean id="applicationservice" class="com.services.applicationserviceimpl" /> <!-- declare datasource bean --> <bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="oracle.jdbc.driver.oracledriver" /> <property name="url" value="jdbc:oracle:thin:@172.21.51.32:1521:sid" /> <property name="username" value="uname" /> <property name="password" value="pwd" /> </bean> </beans> web.xml file <?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>springjdbctemplate</display-name> <welcome-file-list> <welcome-file>appmgt_addnewapp.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> </web-app> , these jars using. ![these jars using.][1]
the error is, in jsp should modelattribute="application"
:
<form:form method="post" action="/insert" modelattribute="application">
ps: you'd better add method="post"
in @requestmapping
Comments
Post a Comment