我想使用类似的网址
主机/ActionName/123/abc/
而不是像这样传递查询字符串
主机/ActionName?parm1=123&parm2=abc
如何在 Struts 2 中做到这一点?
我按照下面的方法做了,但它不起作用,显示 500 错误代码
<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 是不可能的。作为解决方法,您可以使用 UrlRewriter filter 来执行此操作。从 Struts2 2.1+ 开始,借助通配符,您可以使用诸如 host/ActionNmae/param1-123/param2-abc
的内容,请参阅 this发布,但不像 host/ActionNmae/123/abc/
。不同之处在于,第二种情况没有参数名称。解决方法是使用 Parameters after the action name .
@Action(value = "/ActionNmae/*/*", params = {"param1", "{1}", "param2", "{2}"}
关于java - 在 Struts 2 中传递 URL 参数而不使用查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14411736/