zoukankan      html  css  js  c++  java
  • spring MVC做form提交Neither BindingResult nor plain target object for bean name 'command' available

    我的改正是在form表单上添加了个modelAttribute="employee"
    然后在

    @RequestMapping(value="/emp",method=RequestMethod.GET)
    public String input(Map<String,Object> map){
    map.put("departments",departmentDao.getDepartments());
    map.put("employee",new Employee());
    return "input";

    }中添加了一行代码map.put("employee",new Employee());


    这两天在做spring3.0 MVC+hibernate3.2的练习中,做简单的form提交, 一直报java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute 查了好多资料都没有办法解决(有可能是报的错误一样却引起的原因不一样吧),最后还是发现自己在jsp的form标签上写少了commandName属性, 后来加上就可以了。 报错时的代码:<form:form method="post" action="addContact.html"> 修正后的代码:<form:form method="post" action="addContact.html" commandName="contact"> Spring给我们提供了一个commandName属性,我们可以通过该属性来指定我们将使用Model中的哪个属性作为form需要绑定的command对象。 除了commandName属性外,指定modelAttribute属性也可以达到相同的效果。 
  • 相关阅读:
    OpenGL相关文章
    gluOrtho2D与glViewport
    QOpenGLWidget
    openGL中的gl,glu,glut
    QT对话框
    QT布局
    QT容器类
    [POJ1014]Dividing(二进制优化多重背包)
    [Codefroces401D]Roman and Numbers(状压+数位DP)
    [HDU6326]Monster Hunter(贪心)
  • 原文地址:https://www.cnblogs.com/wth21-1314/p/10432302.html
Copyright © 2011-2022 走看看