springspring-mvccontrollermodelattributetwo-way-binding

Concept of Two-Way data binding in Spring MVC


This is my login.jsp file.

<form:form method="POST" action="checklogin" modelAttribute="log">

        <form:label path="username">UserName: </form:label> 
        <form:input path="username" id="username" /><br /><br />
        <br /> 
        <form:label path="pswd">Password: </form:label>
          
         <form:password path="pswd" id="password" /><br /> <br />
        <br /> 
        <input type="submit" id="btnLogin" value=login class="login" />
</form:form>

This is my controller

@RequestMapping(value = "/checklogin", method=RequestMethod.POST)
    public String chklogin(@ModelAttribute Login login, Model mod) {    

        if (login.getUsername().equals("subro") && login.getpswd().equals("ss")) {
            mod.addAttribute("log",login);
            return "Home";
        }
        else {
            return "Login";
        }
    }

Still I am getting the error as Neither BindingResult nor plain target object for bean name 'log' available as request attribute


Solution

  • Change

    @ModelAttribute Login login
    

    To

    @ModelAttribute Login log