In this tutorial session we will discuss about struts 2 packages.Struts 2 packages are like java packages where actions can be grouped together. See a sample package below.
<package name="default" namespace="/" extends="struts-default">
<action name="login">
<result>/menu/login.jsp</result>
</action>
<action name="authendicate" class="com.rajesh.Authendicate" method="verify">
<result>/menu/success.jsp</result>
</action>
</package>
We can provide four parameters with package declaration.
- name – Name of the package (required)
- namespace – Namespace for the actions in the package
- extends – Parent package to inherit
- abstract – If true this package will only be used to define inheritable components not actions. (Discuss in detail later)
- The main use of packages are we can group similar actions together.
- We can inherit one packages options to another one simply by extending it.
- An example is we can group all the actions that required authentication, then by adding particular rule for that package alone we can control the unauthorized access.
Most of the Struts 2 Framework default classes and functionality methods are grouped into packages. We can make use of those by simply extend it. See our example code above, we extended the “struts-default” package where major struts 2 default implementations are available.
]]>