Table of Contents
Description
The ActionMapper interface provides a mapping between HTTP requests and action invocation requests and vice-versa.
...
With method-prefix, instead of calling baz action's execute()
method (by default if it isn't overridden in struts.xml
to be something else), the baz action's anotherMethod()
will be called. A very elegant way determine which button is clicked. Alternatively, one would have submit button set a particular value on the action when clicked, and the execute()
method decides on what to do with the setted value depending on which button is clicked.
...
Action prefix
With action-prefix, instead of executing baz action's execute()
method (by default if it isn't overridden in struts.xml to be something else), the anotherAction action's execute()
method (assuming again if it isn't overridden with something else in struts.xml
) will be executed.
...
...
Allowed action name RegEx
...
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
...
...
Possible uses of the ActionMapper include defining your own, cleaner namespaces, such as URLs like /person/1, which would be similar to a request to /getPerson.action?personID=1 using the DefaultActionMapper.
...
It is configured through struts.xml. For example, with the following entries in struts.xml
...
xml
...
When CompositeActionMapper#getMapping(HttpServletRequest, ConfigurationManager)
or CompositeActionMapper#getUriFromActionMapping(ActionMapping)
is invoked, CompositeActionMapper
would go through these ActionMappers in sequence starting from ActionMapper identified by struts.mapper.composite.1
, followed by struts.mapper.composite.2
and finally struts.mapper.composite.3
(in this case) until either one of the ActionMapper return a valid result (not null) or it runs out of ActionMapper in which case it will just return null for both CompositeActionMapper#getMapping(HttpServletRequest, ConfigurationManager)
and CompositeActionMapper#getUriFromActionMapping(ActionMapping)
methods.
For example with the following in struts.xml:
...
...
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
...
PrefixBasedActionProxyFactory
...
ActionMapper and ActionMapping objects
The ActionMapper fetches the ActionMapping object corresponding to a given request. Essentially, the ActionMapping is a data transfer object that collects together details such as the Action class and method to execute. The mapping is utilized by the Dispatcher and various user interface components. It is customizable through struts.mapper.class
entry in struts.properties
or struts.xml
. Note that the value of this constant is the name of the bean of the new mapper.
Customize
...
Custom ActionMapper must implement ActionMapper interface and have a default constructor.
...
...
See also: RestfulActionMapper
...