0

Is it possible in Struts2 to map URL/actions to different extensions? e.g. if my app is hosted as

http://stack.com/myapp 

Can I have 2 URLs

http://stack.com/myapp/act.action 

and

http://stack.com/myapp/donoact.do

with no mapping for /act.do and /donoact.action. i.e. a URL should be available on single extension.

Using <constant name="struts.action.extension" value="action,do" /> makes the URLs available on both extensions.

Roman C
  • 49,761
  • 33
  • 66
  • 176
SVashisth
  • 131
  • 10
  • http://stackoverflow.com/q/12607075/1700321. – Aleksandr M Oct 29 '14 at 10:23
  • Thanks for prompt reply Aleksandr. But the above doesn't address my problem. Actually I need to apply security and other filters on *.action URLs and bypass *.do. If I use "action.extension" constant URL's are available on both extensions. I don't want that – SVashisth Oct 29 '14 at 10:30
  • 1
    So you want some actions with .do and some with .action? Namespaces are usually used for security constraints and filters. – Aleksandr M Oct 29 '14 at 10:50
  • 1
    Why do you want to do that ? Which is your real use-case ? Which distinction are you trying to make by using most likely the wrong instrument (the extension) ? **Beware of [the XY Problem](http://meta.stackexchange.com/a/66378/214186)** – Andrea Ligios Oct 29 '14 at 10:59
  • 1
    I agree Andrea. Thanks Aleksandr, namespace seems a better approach to the solution. I have suggested the solution to my client, let's see what they agree upon. – SVashisth Oct 29 '14 at 12:54

1 Answers1

0

You can map an action by name and namespace, but can't map by extension. When Struts2 default ActionMapper is determined an action name from the URL it strips the extension and place a namespace and action name using separate properties of ActionMapping.

Lately, this action mapping is used to find the action config used to build and invoke the action instance.

See more about action configuration on Struts docs site.

Roman C
  • 49,761
  • 33
  • 66
  • 176