Versions Compared

Key

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

...

Note

Similar functionality can also be implemented using a custom ActionMapper. The ActionMapper will need to parse the namespace and request itself to set parameters on the matched action. The default ActonMapper is responsible for invoking the PatternMatcher.

Parameters after the action name

To use parameters in the URL, after the action name, make sure this is set:

...

When a URL like /edit/person/123 is requested, EditAction will be called, and its "id" field will be set to 123.

Advanced Wildcards

From 2.1.9+ regular expressions can be defined defined in the action name.

The regular expressions can be in two forms, the simplest one is {FIELD_NAME}, in which case the field with the FIELD_NAME in the action will be populated with the matched text, for example:

Code Block
XML
XML

<package name="books" extends="struts-default" namespace="/">
    <action name="/{type}/content/{title}" class="example.BookAction">
	<result>/books/content.jsp</result>
    </action>
</package>

In this example, if the url /fiction/content/Frankenstein is requested, BookAction's field "type" will be set to "fiction", and the field "title" will be set to "Frankenstein".

The regular expression can also be in the form {FIELD_NAME:REGULAR_EXPRESSION}. The regular expression is a normal Java regular expression. For example:

Code Block
XML
XML

<package name="books" extends="struts-default" namespace="/">
    <action name="/{type}/{author:.+}/list" class="example.ListBooksAction">
	<result>/books/list.jsp</result>
    </action>
</package>

In this example, if the url /philosophy/AynRand/list is requested, ListBooksAction's field "type" will be set to "philosophy" and "author" to "AynRand".

The matched groups can still be accessed using the {X} notation, like:

Code Block
XML
XML

<package name="books" extends="struts-default" namespace="/">
    <action name="/books/{ISBN}/content" class="example.BookAction">
	<result>/books/{1}.jsp</result>
    </action>
</package>

Next: Application Servers