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 filestruts.xml
- <?xml version="1.0" encoding="UTF-8" ?>
- <!DOCTYPE struts PUBLIC "- //Apache Software Foundation//DTD Struts
- Configuration 2.1//EN" "http://struts.apache.org/dtds/struts 2.1.dtd">
- <package name="default" extends="struts-default">
- <action name="product" class="com.javatpoint.Product">
- <result name="success">welcome.jsp</result>
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:
- 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:
- 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:
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.
There are numerous different components likewise, for example, global-special case mappings, global-results, include and so on. It will be talked about later.