Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8525839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:05:54+00:00 2026-06-11T08:05:54+00:00

I am using Spring MVC 3 and I try to use the validation annotation

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:05:56+00:00Added an answer on June 11, 2026 at 8:05 am

    Try adding in your resource message properties file a property with typeMismatch key.

    In a generic way for any typeMismatch error:

    typeMismatch=This is a not valid type
    

    or more specific, to a concrete property:

    typeMismatch.person.age=This is a not valid a type
    

    This will prevent Spring to throw an exception and corresponding message will be added to your errors.

    Hope this helps.

    Update:

    You have to add this bean in your servlet-context.xml:

    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
            p:basename="/WEB-INF/messages/validation" />
    

    And add file validation.properties in /WEB-INF/messages folder with values mentioned above (typeMismatch...).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Spring MVC with Hibernate. My page has a button that creates
I'm using Spring MVC and jquery autocomplete, my spring controller looks like this @RequestMapping(value
I'm using spring MVC, and I have a custom authentication/security system that I had
I'm using Spring's form tag library in a Spring MVC application that I am
I have configured in following way that spring MVC app using Spring 3.1.1.RELEASE web.xml
I am using spring 3 mvc/security frameworks. I have created a Controller class that
Using MVC and trying to use dependency injection for controllers, but when I try
I am using spring mvc in my application,when i created user i have to
I am using Spring MVC 3.1.x with Tiles 2.2.2 (bootstrapped project with Roo) and
I am using spring MVC 3.0 with the jqgrid plugin. I am building the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.