1

I'm trying to change the way urls are mapped in Struts 2.

I would like to be able to set up a url like www.site.com/login.action and have it look like www.site.com/action/login

I understand I can remove the action extension using the struts.xml constant

<constant name="struts.action.extension" value="" />

I updated web.xml with the following:

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/action/*</url-pattern>
</filter-mapping>

This gives me the results I'm wanting routing all /action/ urls to Struts. The problem is Struts doesn't realize the action part of the url is really the action extension...and of course I wouldn't expect Struts to know that. So in all my Struts.xml action mappings I'm having to include /action in the namespace or even in the action name.

I've seen the PrefixBasedActionMapper class and I'm wondering if I'm on the right track to accomplishing what I'm trying to do...or maybe not...and maybe it's not even possible.

Anyone have some insight into this?

  • 1
    I don't understand, with no action extension, what do you mean by recognizing the action part of the url as the extension? Why would you need to? – Dave Newton Jul 06 '12 at 22:55
  • I get the feeling you are telling us what you are trying to do and not what you want. I can definitely get why you want no action extension (they're pointless), but why would you want the /action part? Why not www.site.com/login or www.site.com/account/login or something more meaningful? – Steven Benitez Jul 08 '12 at 04:17
  • I need some sort of indicator in the url (i think) so that tomcat knows that struts needs to deal with this url. We have lots of other urls that struts doesn't need to deal with. Normally you use an action extension for this and b/c struts knows that you don't have to add the extension into all the action mappings, url tags, etc. I was hoping a could achieve something similar with a /action so that I don't have to add that in everywhere...but maybe I do. – Richard McKenzie Jul 10 '12 at 01:24

1 Answers1

0

It looks like you want to create REST-like links on your application. Have you considered something like the REST plugin http://struts.apache.org/2.1.6/docs/rest-plugin.html ?

mmalmeida
  • 1,037
  • 9
  • 27