Passing parameters in URL without query string in Struts 2

后端 未结 2 788
猫巷女王i
猫巷女王i 2020-11-30 13:04

I Like to use URLs like host/ActionName/123/abc/, instead of passing query string like host/ActionName?parm1=123&parm2=abc.

How can I

相关标签:
2条回答
  • 2020-11-30 13:49

    You can use either the namedVariable or regex pattern matchers.

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

    0 讨论(0)
  • 2020-11-30 13:54

    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}"}  
    
    0 讨论(0)
提交回复
热议问题