Using JSTL to compare strings keeps failing.
Environment TOMCAT 7.0.47 JRE6
I have already imported the taglib:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Here is the code:
<c:forEach var="result" items="${resultList}">
<tr>
<td>${result.DIV}</td>
<td>${result.DIV_NAME}</td>
<td>${result.STAFF_CODE}</td>
<td>${result.STAFF_NAME}</td>
<td>
<c:choose>
<c:when test="${result.STAFF_TYPE == 'DOC'}">DOCTOR</c:when>
<c:when test="${result.STAFF_TYPE == 'RES'}">RESIDENT</c:when>
<c:when test="${result.STAFF_TYPE == 'TRE'}">TRAINEE</c:when>
<c:otherwise>no</c:otherwise>
</c:choose>
</td>
<td>${result.STAFF_FLAG == 1 ? 'A' : (result.STAFF_FLAG == 2 ? 'B' : '其他')}</td>
</tr>
</c:forEach>
The result.STAFF_TYPE part keeps failing and always goes into the <c:otherwise> block, displaying "no" on the page.
However, the result.STAFF_FLAG part works fine and shows 'A' or 'B' as expected.
I have already tried the following:
- Changing == to eq:
<c:when test="${result.STAFF_TYPE eq 'DOC'}">DOCTOR</c:when>
But it didn't make any difference.
- Printing out result.STAFF_TYPE to check if I really received the data:
<c:otherwise>${result.STAFF_TYPE}</c:otherwise>
This correctly showed 'DOC', 'RES', 'TRE', which means I am indeed receiving the data.
I have read the following articles:
Any help would be greatly appreciated.
Thanks.