检查Struts2标签中的请求参数值
我的 jsp: 中有以下代码:
<s:property value="#parameters['test']"/>
<br/><s:property value="'1'.equals(#parameters['test'])"/>
现在如果我像这样访问此操作: test.action?test=1
我得到以下信息:
1
false
想知道为什么 1 不等于 1?
I have the following code in my jsp:
<s:property value="#parameters['test']"/>
<br/><s:property value="'1'.equals(#parameters['test'])"/>
now if I access this action like this:
test.action?test=1
I get the following:
1
false
Wondering, why 1 is not equal to 1?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:
OGNL 中的
""
(双引号)和''
(单引号)之间存在差异。双引号将单个字符评估为字符串,而单引号将单个字符评估为字符类型。您可以将多个字符放在单引号中,它将被视为字符串。
进一步的请求范围不是
,但
可以在 jsp 的最后 5 行中看到。
JSP
Test.jsp(Action)
封装struts2;
导入 com.opensymphony.xwork2.ActionSupport;
Edit:
There is a difference between
""
(double quotes) and''
(single quotes) in OGNL.Double quotes evaluate single characters to strings while single quotes evaluate single characters to Character types. You may put multiple characters in single quotes and it will be evaluated as a string.
Further request scope is not
but
as can be seen below in last 5 lines of the jsp.
JSP
Test.jsp (Action)
package struts2;
import com.opensymphony.xwork2.ActionSupport;
我刚刚发现 #parameters['test'] 返回一个字符串数组。因此,当您说
您实际上是将字符串 '1' 与数组 {'1'} 进行比较时,它会返回 false。也许这是因为有两个参数具有相同的名称,
正确的做法是
I just found that #parameters['test'] returns an array of String. So when you say
you are actually comparing a string '1' with an array {'1'} hence it returns false. Maybe this is because there are two parameters with same name
correct thing to do would be