I am using Spring MVC 3 and I try to use the validation annotation for the model object.
However I found that this validation will only work if there are no exceptions thrown.
Take this pojo for example:
public class Person{
private String name;
@Min(30)
private int age;
}
Now,I will create new Person instance through the html form, the validation work if the type of the age is int.
But if not (for example, user input a string for the age), it will throw an exception.
And I want to know where to catch this exception and put its message in the error form field?
UPDATE:
servlet-context.xml
<mvc:annotation-driven />
<mvc:view-controller path="/" view-name="home" />
<context:component-scan base-package="com.king.controller" />
<mvc:resources mapping="/res/**" location="/res/" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>