Struts2 Tutorial Part 4 – Packages

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.

    1. name        –        Name of the package (required)
    2. namespace   –   Namespace for the actions in the package
    3. extends     –      Parent package to inherit
    4. 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.

This entry was posted in Struts2 and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.