1

the complete code is in github: https://github.com/cuipengfei/MPJSP/tree/master/tmp

in the controller, there is a method that handles the submit:

@RequestMapping(value = "/home", method = RequestMethod.POST)
    public void handleSubmit(Customer model, BindingResult result) {
        System.out.println(model.getUserName());
        result.rejectValue("userName", "required.userName", "user name invalid");
    }

and in jsp, there is a form like this:

<form:form method="POST" action="home" modelAttribute="Customer">

    <table>
        <tr>
            <td>Username :</td>
            <td><form:input path="userName" /></td>
            <td><form:errors path="userName" cssClass="error" /></td>
        </tr>
        <tr>
            <td colspan="3"><input type="submit" /></td>
        </tr>
    </table>
</form:form>

the controllers just rejects value every time, but the error message is not displayed.

the complete code can be found here: https://github.com/cuipengfei/MPJSP/tree/master/tmp

1 Answer 1

1

try to set commandName attribute in your form tag

<form:form method="POST" action="home" commandName="Customer">
Sign up to request clarification or add additional context in comments.

2 Comments

Do you see your output System.out.println(model.getUserName());?
try to make your method return value as String ad return "/home" from handleSubmit()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.