在 Struts 2 中在没有查询字符串的情况下在 URL 中传递参数 [英] Passing parameters in URL without query string in Struts 2

查看:22
本文介绍了在 Struts 2 中在没有查询字符串的情况下在 URL 中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用类似的网址

host/ActionName/123/abc/

而不是像传递查询字符串

instead of passing query string like

host/ActionName?parm1=123&parm2=abc

如何在 Struts 2 中做到这一点?

How can I do that in Struts 2?

我做了如下,但它不起作用,显示 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 是不可能的.作为一种解决方法,您可以使用 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}"}  

这篇关于在 Struts 2 中在没有查询字符串的情况下在 URL 中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆