Struts2 Validation Framework Tutorial with Example

struts2-validation-framework Welcome to Part-3 of 7-part series of tutorials where we will go through different practical aspects of Struts2 Framework. In the last part we Created a Basic Struts2 Application from Scratch. I strongly recommend you to go through the previous articles in case you are new to Struts2. In this article we will learn how to leverage Struts2 Validation Framework in an application. For this we will use StrutsHelloWorld application which we created in previous article as base and starts adding validation logic to it. [sc:Struts2_Tutorials]

Introduction to Struts2 Validation Framework

Struts Action 2 relies on a validation framework provided by XWork to enable the application of input validation rules to your Actions before they are executed. Struts2 Validation Framework allows us to separate the validation logic from actual Java/JSP code, where it can be reviewed and easily modified later. The Struts2 Validation Framework alleviates much of the headache associated with handling data validation, allowing you to focus on validation code and not on the mechanics of capturing data and redisplaying incomplete or invalid data. Validation framework comes with set of useful routines to handle form validation automatically and it can handle both server side as well as client side form validation. If certain validation is not present, you can create your own validation logic by implementing java interface com.opensymphony.xwork2.Validator and plug it into validation framework as a re-usable component. Validator uses XML configuration files to determine which validation routines should be installed and how they should be applied for a given application. validators.xml file contains all common validators declaration. If validators.xml file is not present in classpath, a default validation file is loaded from path com/opensymphony/xwork2/validator/validators/default.xml. The first configuration file, validator-rules.xml, declares the validation routines that should be plugged into the framework and provides logical names for each of the validations. The validator-rules.xml file also defines client-side JavaScript code for each validation routine. Validator can be configured to send this JavaScript code to the browser so that validations are performed on the client side as well as on the server side.

Validators Scope

There are two types of Validators in Struts2 Validation Framework.
  1. Field Validators
  2. Non-field validators
Field validators, as the name indicate, act on single fields accessible through an action. A validator, in contrast, is more generic and can do validations in the full action context, involving more than one field (or even no field at all) in validation rule. Most validations can be defined on per field basis. This should be preferred over non-field validation wherever possible, as field validator messages are bound to the related field and will be presented next to the corresponding input element in the respecting view.
<validators> <field name="bar"> <field-validator type="required"> <message>You must enter a value for bar.</message> </field-validator> </field> </validators>
Code language: HTML, XML (xml)
Non-field validators only add action level messages. Non-field validators are mostly domain specific and therefore offer custom implementations. The most important standard non-field validator provided by XWork is ExpressionValidator.
<validators> <validator type="expression"> <param name="expression">foo lt bar</param> <message>Foo must be greater than Bar.</message> </validator> </validators>
Code language: HTML, XML (xml)

Getting Started

Let us add validation logic to StrutsHelloWorld application that we created in previous article. For this tutorial, we will create an Action class called CustomerAction which will contain few fields. Create a file CustomerAction.java in package net.viralpatel.struts2. customer-action-struts2 Copy following content into it. CustomerAction.java
package net.viralpatel.struts2; import com.opensymphony.xwork2.ActionSupport; public class CustomerAction extends ActionSupport{ private String name; private Integer age; private String email; private String telephone; public String addCustomer() { return SUCCESS; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } }
Code language: Java (java)
Note that CustomerAction class has fields name, email, telephone and age. Also it has a method called addCustomer() which doesn’t have any logic, it just return SUCCESS. Now we will add entry for this new action class in struts.xml file. Open the struts.xml file which will be present under resources folder. And add following content between <package></package> tag.
<action name="customer" class="net.viralpatel.struts2.CustomerAction"> <result name="success">SuccessCustomer.jsp</result> <result name="input">Customer.jsp</result> </action>
Code language: HTML, XML (xml)
Note that we are mapping the CustomerAction class with name customer. Also on success user will be redirected to SuccessCustomer.jsp page. Notice that there is another result tag with name input. Whenever the validation logic encounter some validation error, it redirects the user back to page specified as input. Thus in our example, user will be redirected back to Customer.jsp in case of any errors. Create two new JSPs Customer.jsp (which will contain Customer form) and SuccessCustomer.jsp (which will be displayed on success). struts2-validation-jsp-files Customer.jsp
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>Customer Form - Struts2 Demo | ViralPatel.net</title> </head> <body> <h2>Customer Form</h2> <s:form action="customer.action" method="post"> <s:textfield name="name" key="name" size="20" /> <s:textfield name="age" key="age" size="20" /> <s:textfield name="email" key="email" size="20" /> <s:textfield name="telephone" key="telephone" size="20" /> <s:submit method="addCustomer" key="label.add.customer" align="center" /> </s:form> </body> </html>
Code language: HTML, XML (xml)
SuccessCustomer.jsp
<%@ page contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>Customer Page - Struts2 Demo | ViralPatel.net</title> </head> <body> <h2>Customer Added Successfully.</h2> </body> </html>
Code language: HTML, XML (xml)
We have created Customer.jsp file which will display Customer form. But we don’t have link to this page from our web application. So we will create a link to Customer.jsp from Welcome.jsp page. Open Welcome.jsp page and add following link code into it.
<s:a href="Customer.jsp">Add Customer</s:a>
Code language: HTML, XML (xml)
Now open the ApplicationResources.properties file from /resources folder and add following key/values in it.
name= Name age= Age email= Email telephone= Telephone label.add.customer=Add Customer errors.invalid=${getText(fieldName)} is invalid. errors.required=${getText(fieldName)} is required. errors.number=${getText(fieldName)} must be a number. errors.range=${getText(fieldName)} is not in the range ${min} and ${max}.
Code language: HTML, XML (xml)
Execute the code in Eclipse and see the output. You will see login page. Enter username=admin and password=admin123 and do login. On welcome page you will see a link to Add Customer page. Click on that link and you will see Customer page. struts2-customer-form

Adding Validation Logic

Now we are ready with the basic customer form on which we will add the validation logic. Following will be the validations rules:
  1. Name field is mandatory
  2. Age field is mandatory. It should be a number between 1 and 100.
  3. Email field is mandatory. It should be a valid email address.
  4. Telephone is mandatory.
In order to define validation logic for particular form, we first have to create an XML file which will hold this data. Struts2 define a specific naming convention in defining validation xml files. The format is <ActionClassName>-validation.xml. So for our application we will create a file CustomerAction-validation.xml. Note that this file should be present in the same package as of action class. Create file CustomerAction-validation.xml in package net.viralpatel.struts2. And copy following content into it. struts2-validation-xml CustomerAction-validation.xml
<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"> <validators> <field name="name"> <field-validator type="requiredstring"> <param name="trim">true</param> <message key="errors.required" /> </field-validator> </field> <field name="age"> <field-validator type="required"> <message key="errors.required" /> </field-validator> <field-validator type="int"> <param name="min">1</param> <param name="max">100</param> <message key="errors.range"/> </field-validator> </field> <field name="email"> <field-validator type="requiredstring"> <message key="errors.required" /> </field-validator> <field-validator type="email"> <message key="errors.invalid" /> </field-validator> </field> <field name="telephone"> <field-validator type="requiredstring"> <message key="errors.required" /> </field-validator> </field> </validators>
Code language: HTML, XML (xml)
And that’s it. We just added validation logic to our example. Note that the validations xml file contains different field-validators.

Client Side Validation

It is very easy to add Client Side validation or JavaScript validation to any form in Struts2. All you have to do is to add validate=”true” in form tag in your JSP file. For example open Customer.jsp and add validate=”true” in form tag. Struts2 automatically generates the JavaScript code for client side validation of form.
<s:form action="customer.action" method="post" validate="true"> ... </s:form>
Code language: HTML, XML (xml)

That’s All Folks

Execute the application and test the Customer form with different values. Customer page struts2-customer-form Customer page with errors customer-page-validation-errors Customer page on success customer-page-success

Download Source Code

Struts2_Validation_example.zip (3.6 MB)

Moving On

Now that we have implemented Struts2 Validation framework in our example, we know how exactly struts2 validation is handled. Also we know different types of validators like field-validators and non-field. In next part we will study Tiles framework and implement it in our application.
Get our Articles via Email. Enter your email address.

You may also like...

108 Comments

  1. Niall says:

    Hi there,

    Great resource many thanks. Hey one thing I notice is that if I leave the Customer form empty and submit, then I get the following exception in the log;

    Caused by: java.lang.NoSuchMethodException: net.viralpatel.struts2.CustomerAction.setAge([Ljava.lang.String;)
    at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1206)

    Does Struts2 try and set the field as a String even though the type of it is int ?

    Cheers,
    Niall

    • Hi Niall,
      Thanks for pointing out the error. It seems there is some bug with the current version (There is JIRA ticket on this on Struts2 issue tracker – https://issues.apache.org/struts/browse/WW-2128).
      The problem is when we use generic type as attributes, ognl tries to set it as String. So here the workaround is to use wrapper classes (Int, Float) instead of generics (int, float).
      I am modifying the source code.
      Thanks again.

  2. karan says:

    Hi Viral
    There is a error in the naming CustomerAction-validations.xml….if the name is changed to CustomerAction-validation.xml then only this example work properly else all fields are not validated by the framework …..i hope you will see that issue and post the reply …

    Neways thanx for your nice and easy tutorials…
    Hope u will continue the same.

    • @karan – Thanks for pointing out the error. I have updated the tutorial. Although screenshot is showing correct name class.validation.xml. Thanks again.

  3. karan says:

    Hii Viral ….
    you have rightly said that screen shots are showing the correct name …..i actually saw the corrections from the screen shots when my example was not working …….thanx for updating tutorial so fast …….it will help a lot to starters like me ..

    and how can we change the fonts or colors or alignments of our errror messages shown in this example…this question seems foolish ..but i dont mind bieng a fool …lolzz

    and lastly could you please give a small tutorial on how to internationalize a webpage…actually i m trying this ..but getting some errors on output screen…if not then please post any gud link for all that in reply…..

    Thanx….

  4. Vishwanath Tomar says:

    I like the way you write/explain the things.. I visit many pages, but the page you wrote are very good.

    Thanks, keep it up.

    ~VT

  5. Jagadish says:

    hi Viral,

    A ton thanks for your tutorial. Its working like a charm.

    If you can provide a bit more theory about how these validations actually works, it would be more helpfull.

    Any ways thanks for your work……..Hoping to see lots of useful stuff from you.

    Regards,

    Jagadish

  6. Mayur says:

    It is a really great tutorial..Couldn’t thank you enough.

  7. yourfriendship says:

    thanks !tutorial are very good!

  8. Ashwin says:

    Hi, How do you implement validations with struts having a wildcard mapping? Because i seem to get an error

  9. Abiodun says:

    Thanks viral for the great work. You really simplified things. I was almost giving
    Up on struts until I found ur tutorial. Pls would be grateful if you could include
    Reading from an excel file and writing to an excel file using struts 2

  10. Harsimranjit Singh says:

    Its amazing dear… THE BEST article of struts on entire web that i’v searched like hell.. The best part is you are providing all the required jars, tools and the source code of-course.. I am surely going to come back on your blog, for any kind of reference… keep it up buddy… you’ll succeed..

  11. reza says:

    Hi viral,

    i’ve followed your tutorial. but, when i click the button, the value of the fields fill it’s own label… do i missed something?

    thanks.
    Reza

  12. reza says:

    hi,

    just, ignore my previous post. it iwas my fault, i missed to add some keys on ApplicationResources.properties file.
    Btw, i’m very pleased with your tutorial. thank you so much.

    regards,
    Reza

  13. vijaya says:

    Hi Viral,
    This tutorial is really good,i am just curious to know more about inbuilt validators in struts2.
    regards,
    vijaya

  14. khushboo agrawal says:

    Hi veera,
    This tutorial is helped me alot to learn about struts2 so i want to thank you.

    Thanks

  15. monti says:

    hi viral i mgetting this error when i attempted to run the given code.
    it appeared after pressing the add customer button

    exception

    javax.servlet.ServletException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)

    root cause

    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

    please help me in solving the problem

  16. Sharad says:

    Hi Viral,
    This tutorial helps me a lot…
    Thanks

  17. Sadashiv says:

    Struts2 Validation Framework Tutorial with Example
    when i am going to run the Customer.jsp it’s giving fallowing error please help me

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: An exception occurred processing JSP page /Customer.jsp at line 11

    8:
    9: Customer Form
    10:
    11:
    12:
    13:
    14:

    Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    root cause

    javax.servlet.ServletException: java.lang.ExceptionInInitializerError
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
    org.apache.jsp.Customer_jsp._jspService(Customer_jsp.java:83)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    root cause

    java.lang.ExceptionInInitializerError
    org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:58)
    org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
    org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
    org.apache.jsp.Customer_jsp._jspx_meth_s_005fform_005f0(Customer_jsp.java:104)
    org.apache.jsp.Customer_jsp._jspService(Customer_jsp.java:73)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    root cause

    org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed. (Caused by org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed.) (Caused by org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed. (Caused by org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed.))
    org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:543)
    org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
    org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
    org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
    com.opensymphony.xwork2.util.logging.commons.CommonsLoggerFactory.getLoggerImpl(CommonsLoggerFactory.java:29)
    com.opensymphony.xwork2.util.logging.LoggerFactory.getLogger(LoggerFactory.java:42)
    org.apache.struts2.dispatcher.Dispatcher.(Dispatcher.java:96)
    org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:58)
    org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
    org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
    org.apache.jsp.Customer_jsp._jspx_meth_s_005fform_005f0(Customer_jsp.java:104)
    org.apache.jsp.Customer_jsp._jspService(Customer_jsp.java:73)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    root cause

    org.apache.commons.logging.LogConfigurationException: org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed. (Caused by org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed.)
    org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:397)
    org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
    org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
    org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
    org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
    com.opensymphony.xwork2.util.logging.commons.CommonsLoggerFactory.getLoggerImpl(CommonsLoggerFactory.java:29)
    com.opensymphony.xwork2.util.logging.LoggerFactory.getLogger(LoggerFactory.java:42)
    org.apache.struts2.dispatcher.Dispatcher.(Dispatcher.java:96)
    org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:58)
    org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
    org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
    org.apache.jsp.Customer_jsp._jspx_meth_s_005fform_005f0(Customer_jsp.java:104)
    org.apache.jsp.Customer_jsp._jspService(Customer_jsp.java:73)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    root cause

    org.apache.commons.logging.LogConfigurationException: Invalid class loader hierarchy. You have more than one version of ‘org.apache.commons.logging.Log’ visible, which is not allowed.
    org.apache.commons.logging.impl.LogFactoryImpl.getLogConstructor(LogFactoryImpl.java:385)
    org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:529)
    org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:235)
    org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:209)
    org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
    com.opensymphony.xwork2.util.logging.commons.CommonsLoggerFactory.getLoggerImpl(CommonsLoggerFactory.java:29)
    com.opensymphony.xwork2.util.logging.LoggerFactory.getLogger(LoggerFactory.java:42)
    org.apache.struts2.dispatcher.Dispatcher.(Dispatcher.java:96)
    org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:58)
    org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)
    org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)
    org.apache.jsp.Customer_jsp._jspx_meth_s_005fform_005f0(Customer_jsp.java:104)
    org.apache.jsp.Customer_jsp._jspService(Customer_jsp.java:73)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.29 logs.

    ——————————————————————————–

    Apache Tomcat/6.0.29

  18. shantanu says:

    heya!
    thanx for so many wonderful examples.. i used this code for simple form validation, but m ffacing problem in having more than one field with a name.. like if i want more fields with same name to get validated, by using array for setter-getter in class file, so that it gets validated with same name in .xml file… but its setting the values in text field by “, ” using your code.. plzz help.. refer to:
    first name
    last name
    age
    email

  19. Shekar says:

    Hi Viral, Thanks for this well documented tutorial. However when I tried the example code, I am mgetting the below mentioned error when i attempted to run the given code. This is happening when I press the add customer button

    exception

    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    at java.lang.String.compareTo(Unknown Source)
    at com.opensymphony.xwork2.validator.validators.AbstractRangeValidator.validate(AbstractRangeValidator.java:29)
    at com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.validate(AnnotationActionValidatorManager.java:219)
    at com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.validate(AnnotationActionValidatorManager.java:113)
    at com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.validate(AnnotationActionValidatorManager.java:100)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doBeforeInvocation(ValidationInterceptor.java:142)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:148)
    at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
    at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
    at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)

    Would you please please help me in solving the problem

  20. swapna says:

    Hi Viral ,
    Thank u so much for providing such a Understandable tutorial. Really it”s too Good.

    • @Swapna – Thanks for the kind words :)

  21. Mike says:

    Great tutorial so far. I have one problem – when I add ‘validate=”true”‘ to enable client-side validation, I get the following error message in my browser:

    validateForm_customer is not defined

    I inspected the HTML source and the source of the included validation.js and utils.js files, and there’s definitely no trace of that function. Is there something else that needs to be done to enable JS generation? I’m using Struts 2.2.3 and Tomcat 6.0.32.

    Thanks!

  22. Lansana Bangura says:

    I have tried the tutorials, but I am having difficulties. Each time I run the HelloWorld example, I have a 404 error in the browser. I have used the latest version of tomcat, and Struts, is it because of this or I’d have to use the older versions that were used by you?

    • @Lansana – The 404 error might be coming due to issues in dependencies. Check the server logs. You might have some other exceptions there.

  23. pirateme says:

    org.apache.jasper.JasperException: /Customer.jsp (line: 11, column: 61) The JSP specification requires that an attribute name is preceded by whitespace
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
    org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:164)
    org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:153)
    org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1236)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1450)
    org.apache.jasper.compiler.Parser.parse(Parser.java:138)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:197)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:372)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:352)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:601)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:416)

    i am getting this error while running.Give me a solution…its urgent…..

  24. Mohd Adnan says:

    Hi,

    I would like to ask one thing? suppose our action contains any custom object say User user;

    so how to write validation code for user. I have mentioned user.id and user.firstName as key in validation.xml but it throws an exception while rendering page.

    help me??

  25. Melev says:

    Hi: validation on client side is not working, I don’t see the file: validator-rules.xml, where can i get it? can you provide me some useful information? thanks in advance!

  26. Chandrasekhar says:

    Hi Viral, Your Tutorial is Simply Awesome. Even to say i started likely Struts after visiting your site.
    Thx. But When i executed the above code in the customer screen no validation is happening. Even if i leave all fields empty and click add customer, its adding. I had all names same as like how u gave in ur example…

    • Pramodh H C says:

      Hi, Even I am facing the same prob..Did you find any solution for that.???

  27. Poornima Ramaiah says:

    Everything perfectly fine. I guess, no validation for “telephone” filed.

  28. Sharanabasava K P says:

    Hi, All your tutorials are simply superb. In one glance i learnt many more things in struts2.

    I have a problem in my code that, i have used a drop down list and values r fetching from database. and its displaying fine in jsp page but on actionError i have to reload the list with error msg. Am not getting any clues to do. Please help me to do the stuff.

    Thanks in advance.
    Sharan K P

  29. Rahul says:

    Viral thanks for the tutorial
    but validation is not working
    please provide the solution
    thanks in advance
    Regards
    Rahul

    • Sandeep says:

      Hi, the validate=”true” is not working, has anybody found the solution? if so then can u pls share it across.
      Thanking you in advance.

  30. dz says:

    In the previous article, u said the execute() method is the default method for the Action class,but in the CustomerAction class the method is addCustomer(), it seems you didn’t specify the method in the action tag .Would you explain it? thanks in advance .

  31. rahila says:

    Hi,

    The tutorial is very much helpful,Thanks for this.
    How do we validate credit card details in struts 2?

  32. rahila says:

    @dz

    The method has been specified in the s:submit tag,so on submit this method will be searched for,in the action class.

  33. ramesh says:

    Hi Viral,

    Thanks a lot for your contribution on this tutorial, even i got error while running validating.

    [4/24/12 22:19:56:784 IST] 00000039 filter E com.ibm.ws.webcontainer.filter.FilterInstanceWrapper service SRVE8109W: Uncaught exception thrown by filter IESCWEB: java.lang.NoClassDefFoundError: com.opensymphony.xwork2.validator.ValidatorFactory (initialization failure)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:145)
    at com.opensymphony.xwork2.validator.ValidatorFileParser.addValidatorConfigs(ValidatorFileParser.java:192)
    at com.opensymphony.xwork2.validator.ValidatorFileParser.parseActionValidatorConfigs(ValidatorFileParser.java:72)
    at com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.loadFile(AnnotationActionValidatorManager.java:361)
    at com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.buildClassValidatorConfigs(AnnotationActionValidatorManager.java:252)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1650)

  34. Pramodh H C says:

    Hi Viral,
    I have worked out as per your suggestions. But validation cannot be done.. Can you help me out?

  35. kavita says:

    Sir, where we have to create this above validation (xml) file. I use netbeans 6.9 for struts2.But my program not working properly.can u help me.

  36. gourav sxaena says:

    thanks.
    its really easy to understand.
    but if we want to show error msg. in red font then what we have to do

  37. chpenchalaiah says:

    Very easy to Learn.

  38. Nandkishor says:

    thanks viral ………….
    its very cleanto understand the strut 2 validation …………..
    once again thanks ……………….please explain more theortical……….

  39. Srinivasulu Kummitha says:

    Hi
    The tutorial is very helpful for beginners like me , Thanks a lot.

  40. Augur says:

    I test the source code with Struts 2.3.4.1-all, Validation doesn’t work for me.

    BTW, some information from Struts 2 website.
    <!–
    Add the following DOCTYPE declaration as first line of your XXX-validation.xml file:

    –>

    • Augur says:

      Finally, I solved this by changing the validation file. Just use the following as the first line to my validation file. It does work now!!

  41. Augur says:

    DOCTYPE validators PUBLIC “-//Apache Struts//XWork Validator 1.0.2//EN” “http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd”

    Remove , because it cann’t be posted with them.

  42. Aditya says:

    I got this error when i run this please help

    org.apache.jasper.JasperException
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:500)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:413)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)

    root cause

    Method public java.util.List org.apache.struts2.components.Form.getValidators(java.lang.String) threw an exception when invoked on org.apache.struts2.components.Form@1a8dfb3 – Class: freemarker.ext.beans.SimpleMethodModel
    File: SimpleMethodModel.java
    Method: exec
    Line: 130 – freemarker/ext/beans/SimpleMethodModel.java:130:-1
    org.apache.struts2.components.UIBean.end(UIBean.java:521)
    org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    org.apache.jsp.Login_jsp._jspx_meth_s_005fform_005f0(Login_jsp.java:159)
    org.apache.jsp.Login_jsp._jspService(Login_jsp.java:80)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)

    root cause

    freemarker.template.TemplateModelException: Method public java.util.List org.apache.struts2.components.Form.getValidators(java.lang.String) threw an exception when invoked on org.apache.struts2.components.Form@1a8dfb3
    freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
    freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
    freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
    freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
    freemarker.core.Environment.visit(Environment.java:428)
    freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.Environment.include(Environment.java:1508)
    freemarker.core.Include.accept(Include.java:169)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.Environment.process(Environment.java:199)
    freemarker.template.Template.process(Template.java:259)
    org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:157)
    org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:565)
    org.apache.struts2.components.UIBean.end(UIBean.java:519)
    org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    org.apache.jsp.Login_jsp._jspx_meth_s_005fform_005f0(Login_jsp.java:159)
    org.apache.jsp.Login_jsp._jspService(Login_jsp.java:80)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)

    root cause

    java.lang.NullPointerException
    com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.buildValidatorKey(AnnotationActionValidatorManager.java:229)
    com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.getValidators(AnnotationActionValidatorManager.java:86)
    com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.getValidators(AnnotationActionValidatorManager.java:82)
    org.apache.struts2.components.Form.getValidators(Form.java:265)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
    freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
    freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
    freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
    freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
    freemarker.core.Environment.visit(Environment.java:428)
    freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.Environment.include(Environment.java:1508)
    freemarker.core.Include.accept(Include.java:169)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.Environment.process(Environment.java:199)
    freemarker.template.Template.process(Template.java:259)
    org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:157)
    org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:565)
    org.apache.struts2.components.UIBean.end(UIBean.java:519)
    org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    org.apache.jsp.Login_jsp._jspx_meth_s_005fform_005f0(Login_jsp.java:159)
    org.apache.jsp.Login_jsp._jspService(Login_jsp.java:80)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)

    note

  43. Aditya says:

    please help please its urgent

  44. Anny says:

    Its a great tutorial helpled me a lot

  45. pratul baheti says:

    @ViralPatel and everybody
    (Plz have a look at the following points. If anyone of you find these correct or wrong then please share your view)

    1) errors.required=${getText(fieldName)} is required.
    // Instead of above line it should be ${fieldName} is required. That makes sense. i mean the text of it will be null. so we need to show “fieldname is required”

    2) public String addCustomer() {return SUCCESS; }
    // If we use any other method than execute() we need to mention that method in struts.xml.. but i don’t exactly remember how to add in struts.xml .. Plz give a touch on that part of struts.xml.

    3) We can also extend our CustomerAction to ActionSupport and then overriding validate() we can achieve all these.. then how xml validation is beneficial over validation at class level (ActionSupport).

    Btw you really made an great effort to create a wonderfull tutorial.
    Thanks a lot

  46. prashansa says:

    I want to know if i have 5 form then i have to made 5 ApplicationResources.properties files

  47. sravanthi says:

    hi viral…
    Ur application is good and I executed also.. but in my own Login form application, when I entered currect username and password with validations that time I got correct output but when I entered wrong uname & password that time I need not to get validation errors through properties file… In this time tomcat6.0 server showing one warning that is “”Resource propertyfilename_en.properties not found” … give me any solution

  48. AND says:

    Thank u very much. It is excellent.

  49. Ankur Raina says:

    Hi Viral,
    my actionclass-validation.xml does not get loaded properly due to which server connection is closed, can you help me in undertanding why is it happening?

  50. winston says:

    Hi viral, your tutorials are absolutely fine and being a great help for me in learning new things.
    My query is,how can we validate password and confirm password and displays a error message if both password and confirm password are not matching. i tried it using “expression” validator. validation is working, but error message is not displaying on browser if not matching.plz help me out….

    my code in LoginAction-validation.xml–:

    pwd.equals(cpwd)
    Password’s are not matching

  51. you can alse use the inbuilt method of class ActionSupport
    public String validate()
    here is the example of it

    //-------------EXAMPLE------------------
    public class Adduser extends ActionSupport implements ModelDriven {
    
        User user=new User();
        @Override
        public User getModel() {
            return user;
        }
    
        @Override
        public String execute() throws Exception {
        
            boolean flag=user.addUser(user);
            if(flag)
                return SUCCESS;
           else
                return ERROR;
        }
    
        @Override
        public void validate() {
            if(user.getUsername().length()==0)
            {
                addFieldError("username","Username Is Required");
            }
             if(user.getPassword().length()==0)
            {
                addFieldError("password","Password Is Required");
            }
             
                if(user.getName().length()==0)
            {
                addFieldError("name","Name Is Required");
            }
                 
                 if(user.getDob().length()==0)
            {
                addFieldError("dob","Date Of Birth Is Required");
            }
                 if(user.getState().length()==0)
            {
                addFieldError("state","State Is Rquired");
            }
                 if(user.getCity().length()==0)
            {
                addFieldError("city","City Is Required");
            }
                 if(user.getMobile()&lt;10)
            {
                addFieldError(&quot;mobile&quot;,&quot;Mobile Must Be Of 10 Digits&quot;);
            }
                 if(user.getLandline()==0)
            {
                addFieldError(&quot;landline&quot;,&quot;Please Enter The Landline Number&quot;);
            }
                 if(user.getEmail().length()==0)
            {
                         if(user.getSecurityquestion().length()==0)
            {
                addFieldError(&quot;securityquestion&quot;,&quot;Please Enter A Security Question&quot;);
            }
                   if(user.getAnswer().length()==0)
            {
                addFieldError(&quot;answer&quot;,&quot;Please Enter The Answer&quot;);
            }
                 
            }
        }
    }
    

    • Akhilesh says:

      Thanks, that’ s really a elegant approach. Sounds similar spring mvc

    • Alkaram Ansari says:

      perfect code.
      tested this code in eclipse indigo, apache7, struts2.
      successfully running.
      thanx

  52. Manikandan says:

    Hi i am following your steps. But when i submit the customer form it will sows the following error.

    HTTP Status 500 –
    ——————————————————————————–
    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    java.lang.NullPointerException
    org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
    com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:500)
    org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)

    note The full stack trace of the root cause is available in the Apache Tomcat/6.0.32 logs.

    I don’t know? Why its come? And also how can i link the CustomerAction-validation.xml in this project? I am follows ur steps still i got the above error.
    Help me…

    • Niraj says:

      Hey!
      i think your some of your Jsp pages are containing error.!
      Also,make sure you have all libraries in your project.!

  53. rj4u says:

    I am getting the same error as Manikandan. I get the error only when I add the validate = “true” in the jsp. Please help!

  54. rj4u says:

    More details of the error :

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: Method public java.util.List org.apache.struts2.components.Form.getValidators(java.lang.String) threw an exception when invoked on org.apache.struts2.components.Form@7309eabd – Class: freemarker.ext.beans.SimpleMethodModel
    File: SimpleMethodModel.java
    Method: exec
    Line: 130 – freemarker/ext/beans/SimpleMethodModel.java:130:-1
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:570)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)

    root cause

    Method public java.util.List org.apache.struts2.components.Form.getValidators(java.lang.String) threw an exception when invoked on org.apache.struts2.components.Form@7309eabd – Class: freemarker.ext.beans.SimpleMethodModel
    File: SimpleMethodModel.java
    Method: exec
    Line: 130 – freemarker/ext/beans/SimpleMethodModel.java:130:-1
    org.apache.struts2.components.UIBean.end(UIBean.java:521)
    org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    org.apache.jsp.Login_jsp._jspx_meth_s_005fform_005f0(Login_jsp.java:139)
    org.apache.jsp.Login_jsp._jspService(Login_jsp.java:75)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)

    root cause

    freemarker.template.TemplateModelException: Method public java.util.List org.apache.struts2.components.Form.getValidators(java.lang.String) threw an exception when invoked on org.apache.struts2.components.Form@7309eabd
    freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:130)
    freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
    freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
    freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
    freemarker.core.Environment.visit(Environment.java:428)
    freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.Environment.include(Environment.java:1508)
    freemarker.core.Include.accept(Include.java:169)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.Environment.process(Environment.java:199)
    freemarker.template.Template.process(Template.java:259)
    org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:157)
    org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:565)
    org.apache.struts2.components.UIBean.end(UIBean.java:519)
    org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    org.apache.jsp.Login_jsp._jspx_meth_s_005fform_005f0(Login_jsp.java:139)
    org.apache.jsp.Login_jsp._jspService(Login_jsp.java:75)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)

    root cause

    java.lang.NullPointerException
    com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.buildValidatorKey(AnnotationActionValidatorManager.java:229)
    com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.getValidators(AnnotationActionValidatorManager.java:86)
    com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.getValidators(AnnotationActionValidatorManager.java:82)
    org.apache.struts2.components.Form.getValidators(Form.java:265)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:866)
    freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
    freemarker.core.MethodCall._getAsTemplateModel(MethodCall.java:93)
    freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
    freemarker.core.IteratorBlock.accept(IteratorBlock.java:94)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.IteratorBlock$Context.runLoop(IteratorBlock.java:167)
    freemarker.core.Environment.visit(Environment.java:428)
    freemarker.core.IteratorBlock.accept(IteratorBlock.java:102)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.Environment.include(Environment.java:1508)
    freemarker.core.Include.accept(Include.java:169)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.MixedContent.accept(MixedContent.java:92)
    freemarker.core.Environment.visit(Environment.java:221)
    freemarker.core.Environment.process(Environment.java:199)
    freemarker.template.Template.process(Template.java:259)
    org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:157)
    org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:565)
    org.apache.struts2.components.UIBean.end(UIBean.java:519)
    org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
    org.apache.jsp.Login_jsp._jspx_meth_s_005fform_005f0(Login_jsp.java:139)
    org.apache.jsp.Login_jsp._jspService(Login_jsp.java:75)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)

    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.12 logs.

    • adolf says:

      Hi rj4u, how did you fixed you error, i meet the same one.

      • Gagan says:

        I am also getting the same error, please forward you fixed that error.

  55. xcoder says:

    Hi..I followed the steps
    But when i submitted the customer form it is throwing error in console and redirecting to success page.
    Error:
    SEVERE: Caught exception while loading file net/viralpatel/struts2/CustomerAction-validation.xml
    Connection timed out: connect – [unknown location]
    at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:123)

    • Who Cares' says:

      If your action class is CustomerAction.java, try your vaidation xml file as customer-validation.xml.
      C ya

  56. Hi,

    if I had a validateCustomer method in my class, which validation method would be executed?
    in other words, which validation method prevails: xml or programmatic validation

    thanks!

  57. Kleus says:

    Hi I follow your steps but it seems like the validator is not working.
    Thanks in advance for replying.

  58. Robin says:

    customeraction-validation.xml and ApplicationResources.properties dont match the field and key/values. This is the reason u guys are getting errors when u run the program….
    try to match the fields in both the “ApplicationResources.properties ” file and “CustomerAction-validation.xml” file then the program will work without any errors…….also there is an error in the ‘Form’ tag of “customer.jsp”……please change that to

    once u make the above corrections your program will be error free……
    good luck executing the program guys……….if u guys have issues with bugs u can mail me at [email protected]……..please mention the name of the bug in the subject line…..im a java developer too…..im happy to help fresh minds who are eager to learn

  59. Janu says:

    I am trying to add struts 2 validations in struts 2+spring+hibernate application … but it is not getting effected can you help me

  60. adolf says:

    Same error as rj4u,

    org.apache.jasper.JasperException: Method public java.util.List org.apache.struts2.components.Form.getValidators(java.lang.String) threw an exception when invoked on org.apache.struts2.components.Form@4028a3 - Class: freemarker.ext.beans.SimpleMethodModel
    File: SimpleMethodModel.java
    Method: exec
    Line: 130 - freemarker/ext/beans/SimpleMethodModel.java:130:-1
     

    I am using freemarker-2.3.19.jar , struts2-core-2.3.4.1.jar, xwork-core-2.3.4.1.jar

    • AK47 says:

      @RjforU,Adolf
      Download the project folder shared by them.Replace your lib files with their lib files.It will work.

  61. Paarul says:

    Hi
    My whole framework works well…I validates my form …redirect to form with error message when validation fails but ….when it redirect to the form after validation fail…I lose all my form data. I do not wish for user to re-enter information …I would like to retain all user input and let user update it…only thing I have done different is that I have not used key in the for I have separate label and name…Can you help me please ?

    Thanks

  62. Ryan says:

    error at struts 2 xml validation when using multiple validation per field. im using xwork-validator-1.0.3.dtd

    You must enter a value for bar.

    [/code xml]

    Working fine with single field-validator though.
    ** also tried short-circuit still the same exception

  63. Oddidodd says:

    I needed to add !DOCTYPE for my CustomerAction-validation.xml document. Great tutorial!!!

    <!DOCTYPE validators PUBLIC
             "-//Apache Struts//XWork Validator 1.0.3//EN"
               "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
    

  64. Kshama Joshi says:

    Heloo.. I am a novice here…
    pls help me with the following error

    SEVERE: Caught exception while loading file net/viralpatel/struts2/CustomerAction-validation.xml
    Connection refused: connect - [unknown location]
    	at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:115)
    	at com.opensymphony.xwork2.validator.DefaultValidatorFileParser.parseActionValidatorConfigs(DefaultValidatorFileParser.java:69)
    	at com.opensymphony.xwork2.validator.AnnotationActionValidatorManager.loadFile(AnnotationActionValidatorManager.java:338)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    	at java.lang.Thread.run(Thread.java:619)
    Caused by: java.net.ConnectException: Connection refused: connect
    	at java.net.PlainSocketImpl.socketConnect(Native Method)
    	at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
    	at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    	at javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
    	at com.opensymphony.xwork2.util.DomHelper.parse(DomHelper.java:113)
    	... 63 more
    

    • Fabian says:

      Hey Kshama Joshi,

      i’ve got the same error like:

      "SEVERE: Caught exception while loading file net/viralpatel/struts2/CustomerAction-validation.xml"
      

      solved it by changeing the .dtd transcription in the -validation.xml Doctype to:

      <!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.2//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.2.dtd">
      

      the Open Symphony “xwork-validator.dtd” wasn’t available in the Framework i’ve loaded. so changing the Doctype to the one mentioned above should solve your problem.
      Best Regards Fabi

      • Fabian says:

        sorry the code snippet changed my Doctype:
        i mean you have to add:

        BR Fabi

  65. Faizal says:

    @rj4u and Adolf ,,Just add aappend(.action) to your attribute tag of ur JSP file like

  66. Dipen says:

    hey i have download ur example it works fine but when i try to build my own project everything works fine but client side validation is not performed. should i have to include some pacakges.

  67. Snigdha Batra says:

    Good tutorial!!

  68. I have several runtime error in ecllipse in my struts 2 SImple Login Form. Pl see my errors

    Jun 12, 2013 2:24:03 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
    INFO: Loading global messages from resources
    Jun 12, 2013 2:24:04 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
    SEVERE: Dispatcher initialization failed
    Unable to load configuration. - action - file:/E:/testservlet/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/struts2Login/WEB-INF/classes/struts.xml:8:58
    	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
    	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:390)
    	
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    Caused by: Action class [com.struts2.LoginAction] not found - action - file:/E:/testservlet/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/struts2Login/WEB-INF/classes/struts.xml:8:58
    	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:426)
    	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:370)
    	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:487)
    	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:278)
    	at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
    	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:204)
    	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
    	... 22 more
    Jun 12, 2013 2:24:04 PM org.apache.catalina.core.StandardContext filterStart
    SEVERE: Exception starting filter struts2
    Unable to load configuration. - action - file:/E:/testservlet/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/struts2Login/WEB-INF/classes/struts.xml:8:58
    	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:449)
    	at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
    	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
    	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
    	
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
    Caused by: Unable to load configuration. - action - file:/E:/testservlet/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/struts2Login/WEB-INF/classes/struts.xml:8:58
    	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
    	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:390)
    	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:436)
    	... 20 more
    Caused by: Action class [com.struts2.LoginAction] not found - action - file:/E:/testservlet/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/struts2Login/WEB-INF/classes/struts.xml:8:58
    	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.verifyAction(XmlConfigurationProvider.java:426)
    	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:370)
    	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:487)
    	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:278)
    

    • Manjusha says:

      Hi,
      You dont have all libraries needed in your lib folder.Check it once.

  69. Sushant says:

    Hey i want to know what can i use the datatype for grouping the variable,plz any one know this tell me….im trying to develop the web site blog i have completed 60% but i dont have idea about how can i gruop the reply variable which is automatically increament as per replys will increament…Plz help me in this…

  70. Soumi says:

    Thanks…. all your struts related tutorials are very mush useful as well as helpful..

  71. sunil says:

    Hey really a nice example….
    but i am facing one problem where will i get the ApplicationResources.properties file in netbeans 7.1
    i am getting the output but validations are not getting performed.please help me.
    thanks in advance

  72. Milan says:

    i have struts2-tiles-plugin-2.0.11.2.jar in lib,but when deploy gives this error in console:

    can help me?

    thanks

  73. Milan says:

    i have struts2-tiles-plugin-2.0.11.2.jar in lib,but when deploy gives this error in console:

    can help me?

    thanks

  74. Milan says:

    i have struts2-tiles-plugin-2.0.11.2.jar in lib,but when deploy gives this error in console:

    can help me?

    thanks

  75. subba reddy venna says:

    when i run application i get the following error !!!

    Sep 28, 2013 6:38:05 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
    WARNING: No configuration found for the specified action: ‘Display’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.
    Sep 28, 2013 6:38:06 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
    WARNING: No configuration found for the specified action: ‘Display’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.
    Sep 28, 2013 6:38:08 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
    WARNING: Could not find action or result
    There is no Action mapped for namespace / and action name Display. – [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)

  76. Mr.Chowdary says:

    Article explaning with field level validations is quite impressive.
    But how to validate in case of index based form fields?
    Any Idea is highly appreciated.. :)

  77. sudhakar says:

    when i run application i get the following error !!!
    please help me.

    There is no Action mapped for namespace [/] and action name [Customer] associated with context path [/StrutsExample]. – [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:553)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)
    Nov 18, 2013 3:40:12 PM org.apache.struts2.dispatcher.Dispatcher error
    SEVERE: Exception occurred during processing request: There is no Action mapped for namespace [/] and action name [Customer] associated with context path [/StrutsExample].
    There is no Action mapped for namespace [/] and action name [Customer] associated with context path [/StrutsExample]. – [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:553)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

  78. satya says:

    Hi Virat,
    Its nice tutorial, very help ful for beginners like me.
    I have tried as mentioned in the totorial for client side validation.
    But it is not working.

    Pls update how to implement validation when we are using beans.

    Thanks

  79. Swapnil says:

    How to Skip the validation from Submit Button

    • Amol says:

      simply call the validation method in onblur event

  80. Amol says:

    how to add validation code in struts2

  81. Adeline says:

    Do you mind if I quote a couple of your articles as long as I provide
    credit and sources back to your blog? My
    blog site is in the exact same area of interest as yours and my users would truly benefit from a lot of the information you provide here.
    Please let me know if this okay with you. Cheers!

  82. Raja says:

    Struts2 validation is not working when if you use tag and if you display both the result and the UI form in same jsp .. why?

  83. kaushal jani says:

    I am working with struts2 and with json.
    my client side is on android and when user/client send request in url it should check server validation and store in database and should only return required fields with status and set message.

  84. Ramakrishna K.C says:

    I dint get validate=”true” in customer.jsp. What kind of javascript validation code is added by struts-2? Please explain..

    Thanks:
    Ramakrishna k.c

  85. Bhupesh Upadhyay says:

    from where we have to open -validation.xml in netbeans7.0

  86. Asmita says:

    Hi

    when i put Validate =”true” in JSP i am facing error ,but without validate=”true”it is working fine

  87. Many thanks for the great tutorial. You mentioned to add validate=”true” in form tag to enable javascript validation. It is working fine. But one thing i noticed is that for the very first time (when you click Add Customer button ) , validation is server-side, but after that validation is client side. Do you see that too?

  88. sharon says:

    I have this error when I don’t complete the fields in the form:

    05/01/2015 12:07:09 org.apache.struts2.components.ServletUrlRenderer warn
    ADVERTENCIA: No configuration found for the specified action: ‘login’ in namespace: ‘/pages’. Form action defaulting to ‘action’ attribute’s literal value.
    05/01/2015 12:07:10 org.apache.struts2.components.ServletUrlRenderer warn
    ADVERTENCIA: No configuration found for the specified action: ‘login’ in namespace: ‘/pages’. Form action defaulting to ‘action’ attribute’s literal value.
    05/01/2015 12:07:21 org.apache.struts2.dispatcher.Dispatcher warn
    ADVERTENCIA: Could not find action or result: /FotoMaster/pages/login
    No result defined for action fotomaster.actions.LoginAction and result input – action – file:/D:/FotoMaster/workspaceSharon/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/FotoMaster/WEB-INF/classes/struts.xml:10:69

    When I complete the fields in the form, it works.

    I don’t see the validationForm_login method in the source code, struts2 doesn’t generate it.
    Doesn’t work the validation of struts 2

    Can you help me?

    Thanks

  89. jothivignesh says:

    Bro i am having separate bean class for setter and getter. do i need to create validation.xml for that class??? or action class only?

    Jst for info, i am having 3 classes,
    1)Action class having methods which are configured in struts.xml lik save update viewall delete
    2)bean class having only getter and setter and its constructor
    3)class which having business logic methods which are called by action class methods

  90. subhash says:

    hi

    can u explain how to skip the field-validator in xml like if & else cases?Instead of removing the field-validator,i need to use the if and else cases in xml. (not using the the java bean)
    Thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *