Versions Compared

Key

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

Table of Contents
maxLevel3
minLevel2

Description

Wiki Markup
{snippet:id=javadoc|javadoc=true|url=org.apache.struts2.dispatcher.mapper.ActionMapper}

DefaultActionMapper

By default, the DefaultActionMapper is used:

Wiki Markup
{snippet:id=javadoc|javadoc=true|url=org.apache.struts2.dispatcher.mapper.DefaultActionMapper}

Method prefix

Wiki Markup
{snippet:id=method|javadoc=true|url=org.apache.struts2.dispatcher.mapper.DefaultActionMapper}
Wiki Markup
{snippet:id=method-example|lang=xml|javadoc=true|url=org.apache.struts2.dispatcher.mapper.DefaultActionMapper}

Action prefix

Wiki Markup
{snippet:id=action|javadoc=true|url=org.apache.struts2.dispatcher.mapper.DefaultActionMapper}
Wiki Markup
{snippet:id=action-example|lang=xml|javadoc=true|url=org.apache.struts2.dispatcher.mapper.DefaultActionMapper}

Custom ActionMapper

You can define your own ActionMapper by implementing org.apache.struts2.dispatcher.mapper.ActionMapper then configuring Struts 2 to use the new class in struts.xml

Code Block
langxml

<bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="mymapper" class="com.mycompany.myapp.MyActionMapper" />
<constant name="struts.mapper.class" value="mymapper" />

...

It is configured through struts.xml. For example, with the following entries in struts.xml

Code Block
xml
xml

<constant name="struts.mapper.class" value="composite" />
<constant name="struts.mapper.composite" value="struts,restful,restful2" />

...

For example with the following in struts.xml:

Code Block
xml
xml

<constant name="struts.mapper.class" value="composite" />
<constant name="struts.mapper.composite" value="struts,restful" />

CompositeActionMapper will be configured with 2 ActionMapper, namely "struts" which is org.apache.struts2.dispatcher.mapper.DefaultActionMapper and "restful" which is org.apache.struts2.dispatcher.mapper.RestfulActionMapperRestfulActionMapper. CompositeActionMapper would consult each of them in order described above.

PrefixBasedActionMapper

Wiki Markup
{snippet:id=description|javadoc=true|url=org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper}

PrefixBasedActionProxyFactory

Wiki Markup
{snippet:id=description|javadoc=true|url=org.apache.struts2.

...

factory.PrefixBasedActionProxyFactory}

ActionMapper and ActionMapping objects

...

Warning

Custom ActionMapper must implement ActionMapper interface and have a default constructor.

Code Block
langxml

<bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="mymapper" class="com.mycompany.myapp.MyActionMapper" />
<constant name="struts.mapper.class" value="mymapper" />
Code Block

public class MyCustomActionMapper implements ActionMapper {
  public ActionMapping getMapping(HttpServletRequest request,
                                  ConfigurationManager configManager) {
    ....
  }

  public String getUriFromActionMapping(ActionMapping mapping) {
    ....
  }
}

(lightbulb) See also: RestfulActionMapper

Next: Action Proxy & ActionProxy Factory