JSTL if-else sample with c:out
This is my memo. We can write JSP with using c:choose and c:when, c:otherwise behave as if-else syntax. This example inclues c:forEach and sql:query also. Getting some data from database with sql:query, and show them with c:forEach loop and change display strings after checking some data in c:choose section.
<sql:query var="rs" dataSource="jdbc/DS"> SELECT ID,ACSII_NAME as ANAME, DISP_NAME as DNAME FROM PERSON ORDER BY ID; </sql:query> <c:forEach var="row" items="${rs.rows}"><tr> <td>${row.id}"</td> <c:choose> <c:when test="${row.dname != null && row.dname != ''}"> <td><c:out value="${row.dname}" /></td> </c:when> <c:otherwise> <td><c:out value="${row.aname}" /></td> </c:otherwise> </c:choose> </tr></c:forEach>