Dataconversion validating xml

Here, we will take an example of an Employee whose name and age should be captured using a simple page, and we will put these two validations to make sure that the user always enters a name and age which should be in a range between 28 and 65.Let us start with the main JSP page of the example.The best practices suggest that the validation should be introduced at all levels of your application framework.Now let us look at two ways of adding validation to our Struts project.Let us write main page JSP file index.jsp, which will be used to collect Employee related information mentioned above.The makes use of Struts tag, which we have not covered yet, but we will study them in tags related chapters.You will see the following result − Enter the required information but enter a wrong From field, let us say name as "test" and age as 30, and finally click on Submit button.

Another thing to note is the validator types that are available by default.

Struts2 XML based validation provides more options of validation like email validation, integer range validation, form validation field, expression validation, regex validation, required validation, requiredstring validation, stringlength validation and etc. So, in our case we create a file called with the following contents − Rest of the setup will remain as it is i the previous example, now if you will run the application, it will produce same result what we received in previous example.

The advantage of having an xml file to store the configuration allows the separation of the validation from the application code.

Check the following link for more detail Struts - XML Based Validators.

I have an invoice in the form of a PDF and I need to convert that into c XML format.

Leave a Reply