我在春季MVC 3.2 + JDBC项目中遇到了这种错误。
“ HTTP状态500-java.lang.IllegalStateException:BeanResult'app'的BindingResult或纯目标对象都不能用作请求属性”
我已经看到我的人民问了这个问题。我已经回答了。但nbothing为我工作。请帮我 。提前致谢。
这是我的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";
}
}
这是我的ApMgt_AddnewApp.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>
<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>
这是我的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"
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 to take care of annotations stuff -->
<context:annotation-config />
<!-- declaring base package -->
<context:component-scan base-package="com" />
<!-- adding view resolver to 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>
this is my 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>
and these are the jars am using.
![These are the jars am using.][1]
最佳答案
错误是,在jsp中应该为modelAttribute="application"
:
<form:form method="post" action="/insert" modelAttribute="application">
PS:您最好在
method="POST"
中添加@RequestMapping