Tuesday, 3 December 2013

Role of struts.xml file

If you are making a project in struts2 so you must know about the role and responsibility of struts.xml file.

Hello , I am struts.xml file and I am so much proudy because ……

1. If any request comes for serve so without my knowledge and direction, It cannot go further.
2. I am core configuration file for the struts framework and should reside on the classpath of the webapp (most probably  in /WEB-INF/classes folder)
3. I can define the different packages for different module so you can easily find the action request.

Example :

<struts>
<constant name="struts.devMode" value="true" />
<package name="aoiblog" namespace="/aoiblog" extends="struts-default">
 <!-- Add actions here -->
</package>
<package name="aoiblogTwo" namespace="/Two/aoiblog" extends="aoiblog">
 <!-- Add actions here -->
</package>
<!-- Add packages here -->
</struts>

 4. I can also define the namespace so you can get the separate URL for each request serve.

Example :

<package name="aoiblog" namespace="/aoiblog" extends="struts-default">


5.Mostly I am extending the property of struts-default but you can update it to default properties.

Example :

<package name="aoiblog" namespace="/" extends="struts-default">

6.You can break up me in different unlimited xml file but you have to include it in me.

Example :

<struts>
.....
 My Configuration Code
......
<include file="myfile1.xml"/>
<include file="myfile2.xml"/>
.....
 My Configuration Code
.....
</struts>

7. You can define the global error configuration in me.
8.  I have a Interceptors that can preprocess and postprocess a request.
9.  My Action classes that can call business logic (Action Java Class) and data access code
10. I can serve you multiple result as per request define.

Structure of struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="aoiblog" namespace="/aoiblog" extends="struts-default">
<action name="HelloWorldAction">
<result>/aoipages/HelloWorld.jsp</result>
</action>
<!-- Add actions here -->
</package>
<!-- Add packages here -->
</struts>

 Hope you like explaination about the struts.xml file. if you have any query so please put your comment so i can revert back to you.

No comments:

Post a Comment