JSP 를 사용할때

HTML 내에서 if-else 구문을 사용하고 싶다면 JSTL 의 c:choose 를 사용하면 된다. 

<c:choose>

<c:when></<c:when>

<c:otherwise></c:otherwise>

</c:choose>

 

 

사용법>

 

경우1>

<c:choose> 가 if-else 구문의 영역이고

    <c:when test="조건">실행</c:when> 에 if(조건) 구문을 쓰고 실행하고 싶은 구문을 쓰면된다. 

    <c:otherwise>실행</c:otherwise> 에 else 구문을 쓰면된다.

</c:coose>

 

 

코드>

<!-- if-else 구문 -->

<c:choose>

    <!-- if -->

    <c:when test="${sessionScope.member_id=='admin'}">

        ...

    </c:when>

    <!-- else -->

    <c:otherwise>

        ...

    </c:otherwise>

</c:choose>

 

 

경우2>

만약 else if(조건)을 추가 하고 싶다면

<c:choose> 가 if-else 구문의 영역이고

    <c:when test="조건">실행</c:when> 에 if(조건) 구문, 실행하고 싶은 구문을 쓰고

    <c:when test="조건">실행</c:when> 에 else if(조건) 구문을 쓰고 실행하고 싶은 구문을 쓰면된다. 

    <c:otherwise>실행</c:otherwise> 에 else 구문을 쓰면된다.

</c:coose>

 

 

코드>

<!-- if-else 구문 -->

<c:choose>

    <!-- if -->

    <c:when test="${sessionScope.member_id=='admin'}">

        ...

    </c:when>

    <!-- else if -->

    <c:when test="${sessionScope.member_id=='guest'}">

        ...

    </c:when>

    <!-- else -->

    <c:otherwise>

        ...

    </c:otherwise>

</c:choose>

 

+ Recent posts