Explain about validator-rules.xml and validation.xml files ?

Validator framework is used to validate the form data and you no need to write any code in your form bean for validations and storing the error messages.Your Form Bean, extending one of the Validator’s Action Form subclasses, does the required validations.If you do not use Validator, you need to handle the data validations in the validate() method of Form Bean objects, and also handle storing of error messages if validationis fails.

Two configuration files used by Validator are validation.xml and validator-rules.xml. In order to enable and use the Validator, plug-in should be added in sturts-config.xml

<plug-in className=”org.apache.struts.validator.ValidatorPlugin”>
      <set-property property=”pathnames”

validator-rules.xml: This declares the validation routines and logical names are provided for the validations.It is also contains the client side javascript code for each validation routine. This validation routines are java methods plugged into the system to perform the specific validations.

<validator name=”required”

                    <![CDATA[// place the scripts here]]>

If the validation fails when it run, the message(i.e..in ApplicationResources.properties) corresponding to the key specified by the msg attribute will be returned.

validation.xml: This configuration files defines which validation routines must be applied for which form beans. Each form bean you want to validate has its own defination in this file. Inside that definations, you want to apply to the Form Beans’s fields. The definition in the file use the logical names of Form Beans from struts-config.xml file along with logical names of the validation routines from validation-rules.xml to tie together

             <form name=”logonForm”>
                    <field property=”username” depends=”required”>
                                <arg0 key=”prompt.username”/>
                   <field property=”username” depends=”required”>
                                <arg0 key=”prompt.password”/>

The depends attribute specifies the logical names of validation routines from the validator-rules.xml that should be applied to the field.

What is difference between ActionForm and DynaActionForm

If the ActionForm is used, then user himself has to write the setters and getters when ever he adds a control. The same process is repeated again and again when user creates a view. DynaActionForm eliminates this burden and creates the form bean itself. This way user dont have to write setters and getters. No bean class is required for the DynaActionForm and we will declare the form beans as DynaActionForm type in struts-confing.xml. We will declare the properties and their type in the struts-config.xml

<form-bean name=”employeeForm”   type=”org.apache.struts.action.DynaActionForm”>
<form-property name=”name” type=”java.lang.String”/>
<form-property name=”age” type=”java.lang.String”/>

Describe validate() and reset() methods ?

validate() : ActionForm class provides a validate() method hook that can be overridden by subclasses to perform validations on incoming form data.The validate() method hook gets called after a Form Bean has been populated with incoming form data. Following is the method signature for the validate() method

public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)

validate() method has return type ActionErrors

reset(): ActionForm class has a reset() method that subclasses can override. The method is a hook that gets called before FormBean is populated with request data from an HTML form. Using this reset() method, all the form fields will be reset.i.e..Unchecking the check boxes, making the text fileds empty..etc

public void reset() {}

Explain deployment descriptor(web.xml) configuration for struts application ?

Action Servlet and strtus-config.xml files and configured as below


This config parameter tells the Strut’s Action Servlet where to find its central configuration file struts-config.xml


In servlet mapping <url-pattern> tag is sayinng that ActionServlet should process any requests for pages thats end in .do

Tag Library descriptors will be configured as below

<taglib-uri> /WEB-INF/tlds/struts-bean.tld</taglib-uri>
<taglib-location> /WEB-INF/tlds/struts-bean.tld</taglib-location>

Simillarly struts-html.tld,struts-logic.tld will be configured

Is Struts Thread Safe ?

Struts is not only thread-safe but thread-depenedent. The response to a requeast is handled by light weight Action object, rather than an individual servlet.Struts instanciate each Action class once and allows other request to threaded through the orginal object. This core strategy conserves resources and provides the best posible throughput. A properyly-designed application will exploit this further by routing realated operations through a single action.

81. How you will make available any message resources definations file to the struts famework environment.

Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources Definitions files can be added to the struts-config.xml file through <message-resources /> tag.
<message-resources parameter=”MessageResources” />

80. What is Jakarta Struts FrameWork

Jakarta Struts is open source implementation of MVC (Model-View-Controller) pattern for the development of web based applications. Jakarta Struts is robust architecture and can be used for the development of application of any size. Struts framework makes it much easier to design scalable, reliable Web applications with Java.