Struts 2 Configuration File


The struts application contains two principle arrangement documents struts.xml record and struts.properties document.

The struts.properties record is utilized to supersede the default estimations of default.xml document given by struts framework . So it isn't required. Generally, you won't utilize struts.properties document. We will find out about it later.

Here, we will gain proficiency with about struts.xml document. Above all else let us see the basic case of struts.xml file

struts.xml
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC "- //Apache Software Foundation//DTD Struts  
  3. Configuration 2.1//EN" "http://struts.apache.org/dtds/struts 2.1.dtd">  
  4. <struts>  
  5. <package name="default" extends="struts-default">  
  6.   
  7. <action name="product" class="com.javatpoint.Product">  
  8. <result name="success">welcome.jsp</result>  
  9. </action>  
  10.   
  11. </package>  
  12. </struts>      

1) bundle element

We can without much of a stretch separation our struts application into sub modules. The bundle component determines a module. You can have at least one bundles in the struts.xml file.

Attributes of bundle element

  • name name is must for characterizing any package.
  • namespace It is a discretionary quality of bundle. On the off chance that namespace is absent,/is expected as the default namespace. In such case, to summon the activity class, you need this URI:
    1. /actionName.action  
    On the off chance that you indicate any namespace, you need this URI:
    1. /namespacename/actionName.action  
  • extends The bundle component for the most part broadens the struts-default bundle where interceptors and result types are characterized. In the event that you expand struts default, every one of the activities of this bundle can utilize the interceptors and result-types characterized in the struts-default.xml file.

2) activity element

The activity is the subelement of bundle and speaks to an action.

Attributes of activity element

  • name name is must for characterizing any action.
  • class class is the discretionary quality of activity. On the off chance that you exclude the class property, ActionSupport will be considered as the default activity. A straightforward activity might be as:
    1. <action name="product">  
  • method It is a discretionary quality. In the event that you don't determine strategy characteristic, execute technique will be considered as the strategy for activity class. So this code:
    1. <action name="product" class="com.javatpoint.Product">  
    will be same as:
    1. <action name="product" class="com.javatpoint.Product" method="execute">  
    On the off chance that you need to conjure a specific strategy for the activity, you have to utilize technique trait.

It is the sub component of activity that determines where to advance the solicitation for this action.

Attributes of result element

  • name is the discretionary characteristic. On the off chance that you exclude the name property, achievement is expected as the default result name.
  • type is the discretionary property. On the off chance that you exclude the sort property, dispatcher is expected as the default result type.

Other elements

There are numerous different components likewise, for example, global-special case mappings, global-results, include and so on. It will be talked about later.






javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition