2011-04-01 86 views
0

我需要根据从arraylist中提取的值来表示列。JSTL演示问题 - 如果声明

<c:forEach items="${row}" var="cell"> 
     <c:if test="${(cell != 'Read') || (cell !='Write')}" > 
      <td id="access">${cell}</td> 
     </c:if> 
     <c:if test="${(cell == 'Read') || (cell =='Write')}" > 
      <td>${cell}</td> 
     </c:if> 

</c:forEach> 

我有3种类型的值进入单元格读取,写入和其他。对于其他人来说,它将进入!=条件,但对于读写来说,它同时满足两条if语句。我无法使用if-else。 在此先感谢

回答

2

下面是对应的if-else代码的声明,如果第二个如果您的代码作为ELSE。

<c:forEach items="${row}" var="cell"> 
    <c:choose> 
     <c:when test="${cell ne 'Read' or cell ne 'Write'}"> 
      <td id="access">${cell}</td> 
     </c:when> 
     <c:otherwise> 
      <td>${cell}</td> 
     </c:otherwise> 
    </c:choose> 
</c:forEach> 

检查IF中的条件语句。正如voidnnull指出你的第一个IF,而不是使用|| (或)使用& &(和)。

0

这是因为您在第一个测试条件下使用||运算符。

使用& &运算符,它将按预期工作。 <c:if test="${(cell != 'Read') && (cell !='Write')}" >

另外一个的if-else,以构建JSTL,使用<c:choose>标签下,你可以使用<c:when><c:otherwise>。他们的工作方式与if-else类似。

例子:http://www.exampledepot.com/egs/javax.servlet.jsp.jstl.core/if.html