Get all updates of Java4s
Follow Us: Email Newsletter

Struts2 XML Validations Example, Declarative Validations In Struts

Struts » On Oct 25, 2011 { 8 Comments } By Sivateja

In struts 2 we have 3 types of validations

  • Programmatic validations [ manually ]
  • Declarative validations [ xml validations ]
  • Using Annotations

i already explained how we can do programmatic validations,  now will see how to do declarative validations, friends observe am going to use multiple validations rules for the field mail


files required…

  • index.jsp
  • success.jsp
  • error.jsp
  • [ in java4s package ]
  • LogingEx-validation.xml [ in java4s package, must be with that .class file]
  • web.xml [ in web-inf ]
  • struts.xml [ in web-inf/classes folder ]

Directory Structure







Output if enter wrong user/pass


You Might Also Like

  ♦ About Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


8 Responses to “Struts2 XML Validations Example, Declarative Validations In Struts”
  1. Arun says:

    Can we configure single validation.xml in struts 2 for all the action being used in our project?

  2. rishi says:

    Is there any possible to apply XML and programmatic validations in same form?……………….

  3. Nitya says:

    How to properly format the error message.Because the messages are displayed on top of the UI controlls?

  4. Amol Rindhe says:

    How to properly format the error message.Because the messages are displayed on top of the UI?

  5. Not able getting the error messages from from LoginEx-validation.xml

    where we need configure

  6. Chakravarthi says:

    Hi Java4s,

    in which situation we will go for declarative validations and in which situation we will go for programatic validaions can u plz clarify?

  7. Test+user says:

    if we have separate java bean class for form inputs instead having a getter and setter in action class then how we implement the declarative validation?

  8. RKRAJ says:

    Good for beginner


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2016 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.