Q:

Form Error Messages are not displaying in jsp in spring MVC

I added validations to a jsp page the validation is working but messages are not getting displayed.
Below is the code:
JSP:
<body>
<h2>Contact Manager</h2>
<form:form method="post" action="addContact.html">

    <table>
    <tr>
        <td><form:label path="firstname">First Name</form:label></td>
        <td><form:input path="firstname" /><br/></td> 
    </tr>
    <tr>
    <td><font color="red"> <form:errors path="firstname"></form:errors></font></td>
    </tr>
    <tr>
        <td><form:label path="lastname">Last Name</form:label></td>
        <td><form:input path="lastname" /></td>
    </tr>
    <tr>
    <td><font color="red"> <form:errors path="lastname"></form:errors></font></td>
    </tr>
    <tr>
        <td><form:label path="email">Email</form:label></td>
        <td><form:input path="email" /></td>
    </tr>
    <tr>
    <td><font color="red"> <form:errors path="email"></form:errors></font></td>
    </tr>
    <tr>
        <td><form:label path="telephone">Telephone</form:label></td>
        <td><form:input path="telephone" /></td>
    </tr>
    <tr>
    <td><font color="red"> <form:errors path="telephone"></form:errors></font></td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="submit" value="Add Contact"/>
        </td>
    </tr>
</table>    

</form:form>
</body>
</html>

The Following is the configuration:
Spring-servlet.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:property-placeholder location="classpath:resources/jdbc.properties" />
<context:component-scan
        base-package="com.DDD" />
<mvc:annotation-driven />
<bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean>
    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>

    </bean>

        <bean id="dataSource"
            class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="${database.driver}" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.user}" />
        <property name="password" value="${database.password}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>com.DDD.dto.RegisterDto</value>

            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            </props>
        </property>
    </bean>

    <bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <!-- Configuring message properties -->
    <bean id="messageSource"
      class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:resources/messages_en.properties" />
</bean>

</beans>

Following is the controller code:
Controller:
package com.DDD.controller;
import javax.validation.Valid;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;
import com.ezkart.form.Contact;
@Controller
@SessionAttributes

public class ContactController {

    private static final Logger logger = Logger.getLogger(ContactController.class);

    @RequestMapping(value = "/addContact", method = RequestMethod.POST)
    public ModelAndView addContact(@ModelAttribute("contact") @Valid Contact contact, BindingResult result) {
        logger.info("Add Contact is Being Executing");
        if(result.hasErrors()) {
            logger.warn("Requested Fields Has Errors");
            logger.error("Field Error Count:"+result.getFieldErrorCount());
            return new ModelAndView("contact", "command",contact);
        }else{
            logger.warn("Requested Fields Has No Errors");
            return new ModelAndView("contact", "command", new Contact());
        }

        //return "redirect:contact.html";
    }

    @RequestMapping("/contact")
    public ModelAndView showContacts() {
        logger.warn("Contact Page is Being Executed");
        return new ModelAndView("contact", "command", new Contact());
    }
}

Following is the pojo bean:
FORM:
package com.DDD.form;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;
import javax.validation.constraints.Size;

public class Contact {
    @NotEmpty(message = "First Name should not be blank.")
    private String firstname;

    @NotEmpty(message = "Last Name should not be blank.")
    private String lastname;

    //@NotEmpty(message = "Email should not be blank.") @Email
    private String email;

    @NotEmpty(message = "Phone should not be blank.")
    //@Size(min = 5, max = 8, message = "Password length should be between 5 to 8 Characters.")
    private String telephone;

    public String getEmail() {
        return email;
    }
    public String getTelephone() {
        return telephone;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
    public String getFirstname() {
        return firstname;
    }
    public String getLastname() {
        return lastname;
    }
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

}

I don't think property file is necessary but I added it 
PROPERTY FILE:
NotEmpty.user.firstname=User Name can not be blank.
Size.user.name=User Name must be between 5 to 20 characters
Min.user.age= Minimum age must be 5 years
Size.user.location=Location must be between 5 to 50 characters

Where I did I go  wrong 

A:

@Controller
public class ContactController {

    private static final Logger logger = Logger.getLogger(ContactController.class);

    @RequestMapping(value = "/addContact", method = RequestMethod.POST)
    public String addContact(@ModelAttribute("command") @Valid Contact contact, BindingResult result) {
        logger.info("Add Contact is Being Executing");
        if(result.hasErrors()) {
            return "contact";
        }else{
            return "redirect:/contact";
        }
    }

    @ModelAttribute("command")
    public Contact formBackingObject() {
        return new Contact();
    }

    @RequestMapping("/contact")
    public String showContacts() {
        logger.warn("Contact Page is Being Executed");
        return "contact";
        return new ModelAndView("contact", "command", new Contact());
    }
}

Don't mess around with the model, unless you need to. Also you are using the wrong argument in your @ModelAttribute should be command instead of contact. Removed @SessionAttributes as that is doing nothing here.

