2

I want to use URLs like

host/ActionName/123/abc/

instead of passing query string like

host/ActionName?parm1=123&parm2=abc

How can I do that in Struts 2?

I done as below but it is not working, showing 500 error code

<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>

<package name="default" extends="struts-default" namespace="/">
        <action name="/action/*"
    class="gov.apiic.serviceRequest.action.ServiceRequest" method="method" >
    <param name="p1">{1}</param>
    <result name="success">views.jsp</result>
    </action>
</package>
Roman C
  • 49,761
  • 33
  • 66
  • 176
Sagar
  • 980
  • 1
  • 11
  • 27
  • 1
    Its called SEO friendly URL and u can find answer at http://stackoverflow.com/a/5443736/1085285 or http://stackoverflow.com/a/5762548/1085285 – Ashish Gupta Jan 19 '13 at 06:39
  • Thank you very much for your response . I done some effort but no luck. – Sagar Jan 19 '13 at 11:50

2 Answers2

2

It was not possible with plain Struts2 under the 2.1+. As a workaround you can do this with UrlRewriter filter. From Struts2 2.1+ with the help of wildcards you can use something like host/ActionNmae/param1-123/param2-abc see this post, but not like host/ActionNmae/123/abc/. The difference is that in the second case there's no parameter names. The workaround is to use Parameters after the action name.

@Action(value = "/ActionNmae/*/*", params = {"param1", "{1}", "param2", "{2}"}  
Roman C
  • 49,761
  • 33
  • 66
  • 176
1

You can use either the namedVariable or regex pattern matchers.

Each has its own advantages and disadvantages, most of which can be worked around.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Dave Newton
  • 158,873
  • 26
  • 254
  • 302