gpt4 book ai didi

java - HTTP 状态 500 - java.lang.IllegalStateException : Neither BindingResult nor plain target object for bean name 'app' available as request attribute

转载 作者:太空宇宙 更新时间:2023-11-04 06:36:15 25 4
gpt4 key购买 nike

我在 spring mvc 3.2 + jdbc 项目中遇到此错误。

“HTTP 状态 500 - java.lang.IllegalStateException:BindingResult 和 bean 名称“app”的普通目标对象都不能用作请求属性”

我看到我的人问过这个问题。我已经看完了答案。但两者都对我有用。请帮我 。提前致谢。

这是我的 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"/> &nbsp;&nbsp;&nbsp;&nbsp;<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]

these are the jars am using

最佳答案

错误是,在jsp中它应该是modelAttribute="application":

<form:form method="post" action="/insert" modelAttribute="application"> 

PS:最好在@RequestMapping中添加method="POST"

关于java - HTTP 状态 500 - java.lang.IllegalStateException : Neither BindingResult nor plain target object for bean name 'app' available as request attribute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25363403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com