Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment:

Add example configuration

...

To make it easier to access dynamic data obtained by an Action, the framework includes a library of custom tags. The tags interact with the framework's validation and internationalization features, to ensure that input is correct and output is localized. The tag library can be used with JSP, FreeMarker, or Velocity.

Struts Configuration in a Nutshell

A web application uses a deployment descriptor to initialize resources like servlets and taglibs. The deployment descriptor is formatted as a XML document and named web.xml. Likewise, the framework uses a configuration file, named struts.xml, to initialize its own resources. These resources include action mappings, to direct input to server-side Action classes, and result types, to select output pages.

Here's a simple configuration (struts.xml) for a login workflow:

Code Block

<struts>
    <include file="struts-default.xml"/>

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

        <action name="Logon" class="mailreader2.Logon">
            <result name="input">/pages/Logon.jsp</result>
            <result name="cancel" type="redirect-action">Welcome</result>
            <result type="redirect-action">MainMenu</result>
            <result name="expired" type="chain">ChangePassword</result>
        </action>

        <action name="Logoff" class="mailreader2.Logoff">
            <result type="redirect-action">Welcome</result>
        </action>

    </package>
</struts>

Aside from actions and results, you can also specify exception handlers and interceptors. Interceptors specify the "request-processing lifecycle" for an action. (What happens to the request before and after the Action class fires.) You can specify both global and local lifecycles. If some of your actions respond to AJAX, SOAP, or JSF requests, you can simplify the lifecycle, and even just "pass through" the request, if you like.

Struts 2 is extensible. Very extensible. Every class deployed by the framework is based on an interface. We provide base classes, but you can substitute your own. In the case of Action classes, even the interface is optional. POJO web development is here!

The framework provides general-purpose defaults, and you can start using Struts 2 "out of the box". But you can override any of the defaults in your application's configuration. We provide the base framework, but you can still write your application your way.

Getting Started

The online documentation is grouped into three areas.

...