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

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

问题描述

我喜欢使用 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是不可能的。作为解决方法,您可以使用 UrlRewriter过滤器来执行此操作。从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中没有查询字符串的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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