0

I cannot get "remember-me" checkbox value (getting 400 Required boolean parameter 'remember' is not present)

Trying to user @RequestParam. (as for inputs email/password). How to get checkbox value and not 400 error?

Controller


    @RequestMapping(value = "/login", method = RequestMethod.POST)
    private String doLogin(@RequestParam(value = "inputEmail") String inputEmail,
                           @RequestParam(value = "inputPassword") String inputPassword,
                           @RequestParam(value = "remember") boolean remember,
                           HttpSession session) {



HTML form

    <form class="form-login" method="post" action="/login">
                <h2 class="form-login-heading">Please log in</h2>
                <label for="inputEmail" class="sr-only">Email address</label>
                <input type="email" id="inputEmail" name="inputEmail" class="form-control" placeholder="Email address" required
                       autofocus>
                <label for="inputPassword" class="sr-only">Password</label>
                <input type="password" id="inputPassword" name="inputPassword" class="form-control" placeholder="Password" required>
                <div class="checkbox">
                    <label>
                        <input type="checkbox" name="remember" value="remember-me"> Remember me
                    </label>
                </div>
                <button class="btn btn-lg btn-primary btn-block btn-login" type="submit">Log in</button>
            </form>
1
  • Fixed by adding default value parameter in controller. @RequestParam(value = "remember", defaultValue = "false") boolean remember Commented Aug 1, 2016 at 13:09

1 Answer 1

0

Please remove value="remember-me" from your check box.

When you will tick checkbox spring will map string value "remember-me" with Boolean which is not possible as i know.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.