Spring MVC Neither BindingResult nor plain target object for bean name

后端 未结 4 1778
小鲜肉
小鲜肉 2021-01-05 19:59

For some reason I cannot seem to fix this issue, even after looking at multiple examples on here.

I am trying to handle a form using Spring 3 MVC, but I am getting t

相关标签:
4条回答
  • 2021-01-05 20:13

    Try to add @ModelAttribute("reverseString") in your onSubmit method's parameters.

    protected ModelAndView onSubmit(HttpServletRequest request,
            HttpServletResponse response, @ModelAttribute("reverseString") ReverseString revString, BindException errors)
            throws Exception
    
    0 讨论(0)
  • 2021-01-05 20:20

    For me this error was resolved by declaring

    @ModelAttribute("person")
    public Person createFormModelAttribute() {
        return new Person();
    }
    

    in the controller. And also on the jsp, I refer to the model attributes by referencing the class name:

    <form:input  path="person.firstName" />
    
    0 讨论(0)
  • 2021-01-05 20:26

    In your reverse.jsp file, you added modelAttribute as reverseString. So while before loading reverse.jsp, it will look for your ReverseString.java object.

    You just need to add ReverseString.java object in request scope of your controller method from where you navigate user to reverse.jsp.

    e.g.

    @RequestMapping(value = "/getReverseStringForm")
      public String cmLogin(Model model) {
        model.addAttribute(new ReverseString());
        return "reverse";
      }
    
    0 讨论(0)
  • 2021-01-05 20:28

    As I have found out for my self this exception most of cases appears when path to the controller is wrong. Or mistake in syntax. So very carefully check if all links in jsp and paths are right. Because even '/' can be reason of exception.

    0 讨论(0)
提交回复
热议问题