Announcement Announcement Module
No announcement yet.
Error Messages are not displayed in JSP Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error Messages are not displayed in JSP


    I'm new to Spring. I have written a simple example by using the MultiActionController. Once the user submits the login page, im validating the userName and password in validator class. Im calling validator class validate method from a controller. Validations works perfectly and im able to print number of errors in controller, but once its directed to login JSP, its not showing the error messages on the screen. I will appreciate If somebody help me in this regard..thanks....

    Controller Method :

    public ModelAndView onClickLogin(HttpServletRequest request,
    HttpServletResponse response, LoginCommand loginCommand)
    throws Exception {
    * BindException errors = new BindException(loginCommand,
    * "loginCommand"); loginFormValidator.validate(loginCommand, errors);

    // this.preBind(request, loginCommand);
    ServletRequestDataBinder binder = createBinder(request, loginCommand);

    BindException errors = new BindException(binder.getBindingResult());
    if (loginFormValidator.supports(loginCommand.getClass ())) {
    ValidationUtils.invokeValidator(loginFormValidator , loginCommand,

    if (errors.hasErrors()) {
    System.out.println("--------it has some errors21"
    + errors.getErrorCount());
    ModelAndView modelAndView = new ModelAndView("login");
    modelAndView.addObject("loginCommand", loginCommand);
    return modelAndView;
    // LoginCommand loginCommand = (LoginCommand) command;
    System.out.println("Inside the onClickLogin Method");
    AccountDetail accountdetail = accountServices
    ModelAndView modelAndView = new ModelAndView("accountdetail");
    modelAndView.addObject("accountdetail", accountdetail);
    return modelAndView;

    Validator Class

    public class LoginFormValidator implements Validator {

    public void validate(Object command, Errors errors) {
    LoginCommand loginCommand = (LoginCommand) command;

    // checking userName or password is empty
    if ("".equals(loginCommand.getUserId().trim())) {
    errors.rejectValue("userId", "error.userId.empty","UserId should not be empty");
    if ("".equals(loginCommand.getPassword().trim())) {
    errors.rejectValue("password", "error.password.empty", "Password should not be empty");

    public boolean supports(Class clazz) {

    return LoginCommand.class.isAssignableFrom(clazz);


    JSP-Some part

    <form:form method="post" commandName="loginCommand" >
    <spring:bind path="loginCommand">
    <c:forEach items="${status.errorMessage}" var="errorMessage">
    <font color="red"> <c:out value="${errorMessage}" />
    <br> </font>

    <table width="95%" bgcolor="f8f8ff" border="0" cellspacing="0"
    <td alignment="right" width="20%">
    User id:
    <spring:bind path="loginCommand.userId">
    <td width="20%">
    <input type="text" name="<c:out value="${status.expression}"/>"
    value="<c:out value="${status.value}"/>"> <form:errors path="userId" />
    <td width="60%">

    <td alignment="right" width="20%">
    <spring:bind path="loginCommand.password">
    <td width="20%">
    <input type="password"
    name="<c:out value="${status.expression}"/>"
    value="<c:out value="${status.value}"/>"> <form:errors path="password" />
    <td width="60%">

    xml entry

    <bean id="loginBankController"
    class="springexample.contoller.LoginBankController ">

    <property name="authenticationService">
    <ref bean="authenticationService" />
    <property name="accountServices">
    <ref bean="accountServices" />
    <property name="methodNameResolver">
    <ref bean="springBankingMethodResolver" />
    <property name="loginFormValidator">
    <ref bean="loginFormValidator" />

    I have attached the files also. Please refer...