gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:14:51 29 4
gpt4 key购买 nike

我想使用像这样的网址host/ActionName/123/abc/而不是像这样传递查询字符串host/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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com