在<s:if test中如何表达式中添加EL表达式值,并判断。代码写在补充中

在<s:if test中如何表达式中添加EL表达式值,并判断。代码写在补充中,第1张

jstl应该是<c:if></c:if>吧

strust2应该是<s:if></s:/if>

你说的判断应该写成

<c:if test="${empty liep.epTotalMark}">判断不为空;

<c:if test="${not empty liep.epTotalMark}">判断为空。

A:<s:if>判断字符串的问题:

1、判断单个字符:<s:if test="#session.user.username=='c'">

这样是从session中取出username的值,并且判断其是否为c,但是这样判断是不正确的,这样判断的话,根本判断不出来,要改成下面这样:

<s:if test="#session.user.username=='c'.toString()">

这样判断才能正确判断,至于原因我也不知道,在网上看到struts2中可能它判断的是char类型。

2、判断字符串:<s:if test="#session.user.username=='milo'">

这样写的就是判断username是不是milo,是String的判断,这个是不用加toString()的。

3、判断数值:<s:if test="#session.user.username==0">

这样写的就是判断username是不是0,是int的判断。

B:判断为空的问题:

<s:if test="#session.user.username==null">

struts2中的判空似乎只能这么写

判断非空可以这样写:

<s:if test="#session.user.username!=null">

举例:

<s:set name="name" value="model.userId" />

<s:if test="#name == 'luozhh'">

Luozhh's file here

</s:if>

<s:elseif test="#name == 'Scott'">

Scott's file here

</s:elseif>

<s:else>

Other's file here

</s:else>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11936258.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存