从here尝试本教程。
创建了一个动态Web项目和代码。 但是,当我在Tomcat上部署并运行它时,获得此异常:
org.apache.jasper.JasperException:java.lang.IllegalStateException:BindingResult和bean名称'命令'都没有普通的目标对象。可用作请求属性 org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:565) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
我尝试谷歌它并尝试修改控制器类:
package com.tutorialspoint;
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.portlet.ModelAndView;
@Controller
public class StudentController {
@RequestMapping(value="/student", method=RequestMethod.GET)
public ModelAndView student(){
ModelAndView mAndV = new ModelAndView("student");
mAndV.addObject("command",new Student());
return mAndV;
/*return new ModelAndView("student","command",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";
}
}
但它没有帮助...... 我知道这一定是一个简单的问题。但没有得到它是什么。