且构网

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

在 Struts 2 中不带查询字符串的 URL 中传递参数

更新时间:2023-02-24 09:56:45

在 2.1+ 下使用普通的 Struts2 是不可能的.作为一种解决方法,您可以使用 UrlRewriter 过滤器 来执行此操作.从 Struts2 2.1+ 开始,借助通配符,您可以使用类似 host/ActionNmae/param1-123/param2-abc 的内容,请参阅 this 帖子,但不像 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}"}