参见英文答案 > What causes “java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘command’ available as request attribute”? 5个
我收到了这个错误
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
这是堆栈跟踪
org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘command’ available as request attribute
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:534)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:452)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘command’ available as request attribute
org.springframework.web.servlet.support.BindStatus.(BindStatus.java:141)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:178)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:198)
org.springframework.web.servlet.tags.form.LabelTag.autogenerateFor(LabelTag.java:129)
org.springframework.web.servlet.tags.form.LabelTag.resolveFor(LabelTag.java:119)
org.springframework.web.servlet.tags.form.LabelTag.writeTagContent(LabelTag.java:89)
org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:102)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79)
org.apache.jsp.student_jsp._jspx_meth_form_005flabel_005f0(student_jsp.java:182)
org.apache.jsp.student_jsp._jspx_meth_form_005fform_005f0(student_jsp.java:117)
org.apache.jsp.student_jsp._jspService(student_jsp.java:79)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
这是我的web.xml文件
这是我的applicationContext.xml文件
这是我的student.jsp文件
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
这是我的StudentController.java文件
package com.Prime;
import org.springframework.stereotype.Controller;
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 org.springframework.ui.ModelMap;
@Controller
public class StudentController {
@RequestMapping(value = "/student",method = RequestMethod.GET)
public ModelAndView student() {
return new ModelAndView("/student.jsp","SpringWeb",new Student());
}
@RequestMapping(value = "/addStudent",method = RequestMethod.POST)
public String addStudent(@modelattribute("SpringWeb")Student student,ModelMap model) {
model.addAttribute("name",student.getName());
model.addAttribute("age",student.getAge());
model.addAttribute("id",student.getId());
return "result";
}
}