且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Struts 2中传递URL中没有查询字符串的参数

更新时间:2023-02-24 09:34:21

2.1+以下的普通Struts2是不可能的。作为解决方法,您可以使用 UrlRewriter过滤器来执行此操作。从Struts2 2.1+开始,在通配符的帮助下,您可以使用类似 host / ActionNmae / param1-123 / param2-abc 的内容,参见这个帖子,但不像 host / ActionNmae / 123 / abc / 。不同之处在于,在第二种情况下,没有参数名称。解决方法是使用操作名称后的参数

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}"}