在jsp页面上使用c:if判断,判断条件中使用&&进行逻辑判断。 代码如下:
<%
String userComcode = "44This is first String." ;
request.setAttribute("userComcode", userComcode);
%>
${ userComcode } <br>
${ userComcode != null }<br>
${ fn:substring(userComcode, 0, 2) == '44' }<br>
<c:if test="${ fn:substring(userComcode, 0, 4) != '4403' }">
${ fn:substring(userComcode, 0, 4)}
</c:if>
<br>
<c:if test="${userComcode != null && fn:substring(userComcode, 0, 2) == '44' && fn:substring(userComcode, 0, 4) != '4403'}">
显示
</c:if>
在调试过程中遇到一个问题,就是三个条件单独使用的时候都是true,但是合并起来就是不显示 查了很多资料发现写法都没有错误。 最后比对成功执行的发现 test,= ,“” 之间有空格, 把空格取消掉,就成功执行了。我也不明白为何如此神奇。 反正就这么稀里糊涂解决了。