gpt4 book ai didi

java - 获取 java.lang.IllegalStateException : Neither BindingResult nor plain target object for bean name 'command' available as request attribute

转载 作者:行者123 更新时间:2023-11-30 10:41:20 26 4
gpt4 key购买 nike

获取 java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute spring 3.0 错误。我该如何解决?

下面是文件的代码

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Form handling</title>
</head>
<body>
<form:form action="/emp/showEmployee" method="POST">
<table>
<tbody>
<tr><td>Employee Name: </td><td><form:input path="empName"/></td></tr>
<tr><td>Employee Skill: </td><td><form:input path="empSkill"/></td></tr>
<tr><td><input type="submit" value = "Submit"></td></tr>
</tbody>
</table>
</form:form>
</body>
</html>

web.xml

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<!-- Processes application requests -->
<servlet>
<servlet-name>emp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>emp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>/WEB-INF/views/index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

context-config.xml

<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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

EmployeeController.java

 package com.springmvctut.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.springmvctut.bean.EmployeeForm;

@Controller
public class EmployeeController {

@RequestMapping(value = "/employee", method = RequestMethod.GET)
public ModelAndView employee() {
return new ModelAndView("employeeForm", "command", new EmployeeForm());
}
@RequestMapping(value = "/showEmployee", method = RequestMethod.POST)
public String showEmployee(@ModelAttribute("SpringWeb")EmployeeForm employeeForm, ModelMap modelMap){

modelMap.addAttribute("name", employeeForm.getEmpName());
modelMap.addAttribute("skill", employeeForm.getEmpSkill());
return "employeedetails";

}

}

EmployeeForm.java(Bean类)

package com.springmvctut.bean;

public class EmployeeForm {

private String empName;
private String empSkill;
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getEmpSkill() {
return empSkill;
}
public void setEmpSkill(String empSkill) {
this.empSkill = empSkill;
}
public String toString(){
return "Employee name-"+empName+" Employee Skill-"+empSkill;
}

}

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