You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Colin Sampaleanu <co...@Bspark.com> on 2000/08/25 18:06:34 UTC

Easier way to get multiple paths for one action

I need to be able to define multiple paths to the same action handler.
Obviously one way to do it is to have essentially identical 'action' entries
in the action.xml file with only the path changing. This is fine when there
are differences in each mapping anyways, but in this case the only thing
that really needs to change is the path, so it seems like a waste of
resurces never mind more information that must be kept up to date.

Let me describe why I need this and a proposed solution:

In my applications I need to define actions and subactions. The normal way
to do this would be as in the sample app, where the last piece of the path
is the action, and the subaction is a parameter, e.g.
  http://hostname.com/context/actionname.do?subaction=subactionname
or
  http://hostname.com/context/cmd/actionname?subaction=subactionname
This would be fine, except that I want to use the servlet engine to provide
declarative authentication and authorization for different action and
subaction combinations. The only way I can do this is if the URL path also
includes the subaction, e.g.
  http://hostname.com/context/actionname/subaction/cmd.do
or
  http://hostname.com/context/cmd/actionname/subaction/

So I want any request for a path containing stuff up to 'actionname' to go
to a specific action handler, but the rest of the request URL should be
ignored for matching purposes. Right now this will not work since an
ActionMapping only has the concept of one path per handler, and the whole
request path is compared.

I would suggest that an ActionMapping should have a list of paths (e.g. add
AddPath, RemovePath, getPaths methods to ActionMapping), and all paths would
be used and checked. The paths would be declared as such in the action.xml:

  <action    path="/action/subaction"
    actionClass="...>
    <path value="/action/subaction2">
    <path value="/action/subaction3">
	...
    <forward name="success"    path="..."/>
  </action>

The existing 'path' attribute could be used or ignored at will (e.g. if
there is only one path, stick it there, otherwise stick the first path there
and subsequent ones as elements, or stick all paths as elements).

An alternative way of implementing this would be to allow a wildcard
operator, similar to the way that servlet paths are matched, e.g.
  <action    path="/action/*"
    actionClass="...>
	...
    <forward name="success"    path="..."/>
  </action>

This would require the mappings objects to keep two sets of paths, one exact
matching, and one prefix matching (similar to what Tomcat does internally),
and do matches against both.

I think both extensions would be useful. What do you guys think?