0

I migrated from Spring 3 to 5, upgraded to Tomcat 9. After upgrading not able to get the values from JSP to Controller. @ModelAttribute is not binding the values entered in JSP, while submitting the form.

JSP Code:

<form:form action="/login" modelAttribute="identity" id="loginForm" cssClass="clearfix nodisplay">

<div class="grouping text">
    <label for="email">E-mail Address</label>
    <form:input path="email" id="email" cssClass="regInput" cssErrorClass="error" />
    <form:errors path="email" cssClass="errors" />
</div>
<div class="grouping text">
    <label for="pwd">Password</label>
    <form:password path="pwd" id="pwd" cssClass="regInput" cssErrorClass="error" autocomplete="off" />
    <form:errors path="pwd" cssClass="errors" />
</div>
<div class="grouping remember">
    <input type="checkbox" name="remember" id="remember" />
    <label for="remember">Remember Me</label>
</div>
<div class="btns clearfix">
    <span class="login-btn">
        <input type="hidden" name="cookieExist" id="cookieExist" value="false" />
        <button type="button" name="login" class="btn js-login-btn"><span class="pictos">K</span> Login</button>
    </span>
    <span class="password-forget">
        <a href="/passwordreset">I forgot my password</a>
    </span>
</div>
</form:form>

Controller Code

 @Controller
 public class LoginController {

    @RequestMapping(method=RequestMethod.GET, value="/login")
    public String loginGet(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap,
                        @ModelAttribute Identity identity){

        // commented business logic code
        return "login";
    }


    @RequestMapping(method=RequestMethod.POST, value="/login")
    public String loginPost(HttpServletRequest request, HttpServletResponse response,
            ModelMap modelMap, @ModelAttribute("identity") Identity identity, BindingResult bindingResult) {
        //commented out business logic
        return "dashboard";
    }

    @ModelAttribute("identity")
    public Identity formBackingObject() {
        return new Identity();
    }
}

I have migrated with no webxml way, not sure what else i'm missing here?

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
Pruthviraj
  • 1,689
  • 2
  • 14
  • 18
  • Any use? https://stackoverflow.com/questions/37736056/button-type-button-vs-submit – Alan Hay Dec 06 '18 at 18:01
  • I use JS function to submit "form", i tried both ways with `type="submit"` in button as well with `$(this).closest("form").submit();` either way problem exists! – Pruthviraj Dec 06 '18 at 18:08

1 Answers1

0

No need of action here in the form tag. Mention method in the form tag. So chnage to:

<form:form modelAttribute="identity" method="post" id="loginForm" cssClass="clearfix nodisplay">

And also change your primary action button to:

<input type="submit" ... />
Minar Mahmud
  • 2,577
  • 6
  • 20
  • 32