问题描述
我喜欢使用 host / ActionName / 123 / abc /
之类的网址,而不是传递像 host / ActionName这样的查询字符串?parm1 = 123& ; parm2 = ABC
。
I Like to use URLs like host/ActionName/123/abc/
, instead of passing query string like host/ActionName?parm1=123&parm2=abc
.
我如何在Struts2中做到这一点?
How can I do that in Struts2?
我完成如下操作。但它不起作用,显示500错误代码
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>
推荐答案
2.1+以下的普通Struts2是不可能的。作为解决方法,您可以使用来执行此操作。从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}"}
这篇关于在Struts 2中传递URL中没有查询字符串的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!