Wednesday, 19 February 2014

About package Element is Struts ?

The package Element

All the actions are grouped into packages(modules) because Struts has been designed with modularity in mind. A typical struts.xml file can have one or many packages: 

<struts> 
<package name="package-1" namespace="namespace-1" extends="struts-default"> 
<action name="..."/>
<action name="..."/>
 ...
</package> 
<package name="package-2" namespace="namespace-2"  extends="struts-default">
<action name="..."/> 
<action name="..."/> 
... 
</package>
 ... 
<package name="package-n" namespace="namespace-n" extends="struts-default">
<action name="..."/>
<action name="..."/>
 ... 
</package>
</struts>

Attribute                                Mandatory                         Default Value
  name                                      Yes                                     ___
  namespace                             No                                     "/"
  extends                                  No(but important)             ___(but usually struts-default)

Note:-
If the namespace attribute has a non-default value:-
* Then namespace must be added to the URI that invokes the actions in the package.
For example, with default namespace, URI is as below 
/context/actionName.action

but with non-default namespace, URI is 
/context/namespace/actionName.action

**  A package element almost always extends the struts-default package defined in struts-default.xml.
 By doing so, all actions in the package can use the result types and interceptors registered in struts-default.xml.

No comments:

Post a Comment