[英]struts2 if greater than/less than equal etc
I get the feeling this is a bad idea in struts2:我觉得这在 struts2 中是个坏主意:
<s:if test="%{#someVar >= 60}">Hello</s:if>
Is this actually legal?这实际上合法吗? If not what is a better way to check some value within the JSP?
如果不是,在 JSP 中检查某些值的更好方法是什么?
Thanks谢谢
The angle bracket ie >
is legal inside the if
struts tag.尖括号 ie
>
在if
struts 标签中是合法的。 From the link shared by @rees, under the section Appendix: OGNL Language Reference > Operators , you can see this example:从@rees 共享的链接中,在部分附录:OGNL 语言参考 > 运算符下,您可以看到此示例:
e1 >= e2, e1 gte e2
e1 >= e2, e1 gte e2
Greater than or equals comparison大于等于比较
In your case:在你的情况下:
<s:if test="%{#someVar gte 60}">Hello</s:if>
and you don't need the %{}
, as the #
sign is already telling Struts to go and find the someVar on the ActionContext
.并且您不需要
%{}
,因为#
符号已经告诉 Struts 去寻找ActionContext
上的someVar 。 Better still, you don't need the #
sign, if someVar is on the Value Stack
, ie declared as a property in your Action class with getter and setter.更好的是,如果someVar在
Value Stack
上,则不需要#
符号,即在 Action 类中使用 getter 和 setter 声明为属性。
This does not work though:但这不起作用:
<s:if test="%{#someVar >e; 60}">Hello</s:if> <s:if test="%{#someVar
>e; 60}">你好</s:if>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.