【问题标题】:Passing parameters in URL without query string in Struts 2在 Struts 2 中在没有查询字符串的情况下在 URL 中传递参数
【发布时间】:2013-01-02 22:04:21
【问题描述】:

我想使用类似的网址

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>

【问题讨论】:

标签: java parameters struts2 url-parameters wildcard-mapping


【解决方案1】:

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

【讨论】:

  • 是的,你可以,使用模式匹配器映射器(我忘记它叫什么了)。
【解决方案2】:

您可以使用namedVariableregex 模式匹配器。

各有优缺点,大部分都可以解决。

【讨论】:

    猜你喜欢
    • 2013-01-18
    • 1970-01-01
    • 2021-02-06
    • 2012-06-09
    • 2016-09-14
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多