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

Example

files required…

  • index.jsp
  • success.jsp
  • error.jsp
  • LogingEx.java [ 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

index.jsp

success.jsp

error.jsp

LogingEx.java

LogingEx-validation.xml

web.xml

struts.xml

Output if enter wrong user/pass

Output

You Might Also Like

  ::. About the Author .::

Java4s_Author
- Full Stack Java/J2EE & UI Web Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.

Comments

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. 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

Name*
Mail*
Website



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Hibernate Spring Struts
Contact | About Us | Privacy Policy | Advertise With Us

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