java 将参数传递给struts2中的url?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4504164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
passing parameters to urls in struts2?
提问by SonOfTheEARTh
I am working with a struts2 project and i need to pass parameters through url... this is the code that i have written
我正在处理一个 struts2 项目,我需要通过 url 传递参数......这是我编写的代码
<s:url action="submit/CalculatePoints" includeParams="get" var="playerX" >
<s:param name="winnerNo" value="player2"/>
it was refernced by following code
它被以下代码引用
<a href="<s:property value="#playerX" />">
I expected that the markup for the link be
我希望链接的标记是
submit/CalculatePoints?winnerNo=palyer2
submit/CalculatePoints?winnerNo=palyer2
However iam not getting the querystring part. also attribute winnerNo in the action class is not getting populated as it should be according to How to access url parameters in struts2
但是我没有得到查询字符串部分。根据如何访问 struts2 中的 url 参数,操作类中的属性 winsNo 也没有被填充,因为它应该是
Please tell me where i am going wrong?
请告诉我我哪里出错了?
回答by Quaternion
Player2 is being evaluated not as a string but an OGNL expression simply quote Player2 and the issue will be resolved.
Player2 不是作为字符串进行评估,而是作为 OGNL 表达式简单地引用 Player2,问题将得到解决。
IE:
IE:
<s:url action="submit/CalculatePoints" includeParams="get" var="playerX" >
<s:param name="winnerNo" value="'player2'"/>
</s:url>
回答by weltraumpirat
The struts documentation for <s:url>
says this:
The includeParams attribute may have the value 'none', 'get' or 'all'
includeParams 属性的值可能是“none”、“get”或“all”
Since you set this attribute to 'true', the tag seems to be ignored.
Also, you must set the escapeAmp attribute to 'false'. (I assume you have a closing </s:url>
somewhere else in the code).
由于您将此属性设置为“true”,因此该标记似乎被忽略了。此外,您必须将 escapeAmp 属性设置为“false”。(我假设您</s:url>
在代码中的其他地方有一个关闭)。