반응형

JSTL(JavaServer Pages Standard Tag Library, 약칭 JSTL)은 

Java EE 기반의 웹 애플리케이션 개발 플랫폼을 위한 컴포넌트 모음

 

JSP 페이지에 태그라이브러리를 추가한 후 사용해야함

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

문법
1. c:forEach
- 속성
Items : 반복 데이터가 있는 아이템 Collection
begin : 시작번호 기본값 0
end   : 종료번호
step  : 증가분
var   : 현재 아이템의 변수 이름
varStatus : 반복 상태 값을 지닌 변수 
request.setAttribute("AList", list);

- 예제
<c:forEach var= "list" items ="${result}" varStatus="status" >
<tr>
<td> ${list.SEQ}</td>
<td><a href ="/notice/noticeView.do?seq=${list.SEQ} ">${list.TITLE}</a></td>
<td> ${list.W_USR}</td><td> ${list.W_DATE}</td></tr>
</c:forEach>

2. c:if
<c:set var= "변수명" value ="${noticeView.POPUP_TERM_DAY}" />
     <c:if test= "${popup_term_day eq '1'}">
          <option value= '1' > 1일 후까지 노출</option>
     </c:if>

- IF 문장 기본
<c:if test="${pageContext.request.method=='POST'}">
<c:if test="${param.guess=='5'}">
You guessed my number!
</c:if>

<c:if test="${param.guess!='5'}">
You did not guess my number!
</c:if>
</c:if>


- if ~ else 문
<c:if test="${pageContext.request.method=='POST'}">
Ok, we'll send 
<c:out value="${param.enter}" />

<c:choose>
<c:when test="${param.enter=='1'}">
pizza.
</c:when>

<c:otherwise>
pizzas.
</c:otherwise>
</c:choose>
</c:if>


- 논리 연산자 And와 Or을 이용한 if
<c:set var="guess" value="12"/>
<c:out value="${guess}"/>

<c:if test="${(guess >= 10)  && (guess <= 20)}">
<b>You're in range!</b><br/>
</c:if>

<c:if test="${(guess < 10)  || (guess > 20)}">
<b>Try again!</b><br/>
</c:if>


- true 값과 if문의 처리
<c:if test="true">Hello world!</c:if>


- 본문이 없이 if구문 처리하는 예제
<c:if test="${pageContext.request.method=='POST'}">
<c:if test="${param.guess=='5'}" var="result" />
I tested to see if you picked my number, the result was 
<c:out value="${result}" />
</c:if>


- 테스트 결과를 변수에 넣기, 이렇게 해서 결과를 재 사용할 수 있다.
<c:if test="${1==1}" var="theTruth" scope="session"/>

The result of testing for (1==1is: ${theTruth}
<h3>Conditionally execute the body</h3>

<c:if test="${2>0}">
It's true that (2>0)!
</c:if>


- 널과 Boolean 
<c:set var="StrVar" value="true"/>
<c:if test="${StrVar}">
equal!
</c:if><br/>

null == null
<c:out value="${null == null}"/>



2. c:choose
<c:choose>
<c:when test= "${dept_list.DEPT_SEQ == member.DEPT_SEQ}" >
<option value= '1' > 1일 후까지 노출</option>
</c:when>
<c:otherwise>
<option value= '2' > 2일 후까지 노출</option>
</c:otherwise>

</c:choose>


반응형

+ Recent posts