web developer👩🏻‍💻

[JSTL] JSTL이란? core 주요기능 본문

js

[JSTL] JSTL이란? core 주요기능

natrue 2021. 1. 15. 14:01
728x90
JSTL은 JSP 표준라이브러리(JSP Standard Tag Library)의 약어이다.
자주 사용될 수 있는 커스텀 태그들을 모아서 표준으로 모아놓은 태그 라이브러 

 

라이브러리 명 접두어 주요기능  uri 및 사용법 
코어  c 반복문, 제어문,
페이징 처리 관련
 <%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
함수 fn collection 처리,
String 처리
 <%@ taglib prefix="fn"
uri="http://java.sun.com/jsp/jstl/fuctions
" %>
포매팅 fmt 포맷처리,
국제화 지원
 <%@ taglib prefix="fmt"
uri="http://java.sun.com/jsp/jstl/fmt
" %>
데이터베이스 sql DB관련
CRUD처리
 <%@ taglib prefix="sql"
uri="http://java.sun.com/jsp/jstl/sql
" %>
XML x XML
관련 처리
 <%@ taglib prefix="x"
uri="http://java.sun.com/jsp/jstl/xml
" %>

 

 

 코어 core (c)  주요 기능 

 

<c:set>  변수 선언 

 int num = 10;  
 <c:set var="num" value="10"/> 
<c:out>  출력

 System.out.println("natrue"); 
 <c:out value="natrue"/>
<c:remove>  변수값 remove = 삭제 

 <c:remove var="num"/>
<c:if>  if 문

 <c:set var="name" value="naTrue" />
 <c:if test="${name eq 'naTrue'}">
      <p>맞다</p>
 </c:if>

<c:chose>
<c:when> 
<c:otherwise>

 if / else if / else 문
 <c:set var="name" value="naTrue" />

 <c:choose>
     <c:when test="${name eq 'naTrue'}">

        <p>맞다</p>
     </c:when>
     <c:when test="${name eq 'naFalse'}">

        <p>아니다</p>
     </c:when>
     <c:otherwise>

        <p>모르겠다</p>
     </c:otherwise>
 </c:choose>

<c:forEach>  for 문 

 var : 사용할 변수명
 items : Collection 객체 (List, arrayList)
 begin : 시작 인덱스
 end : 끝 인덱스
 step : 증감수
 varStatus 반복 상태를 알수있는 변수 

 <c:forEach var="item" items="${list}" begin=0 end=5 step=1   varStatus="status">
    <tr>
        <th>번호</th>
        <td>${status.count}</td>
        <th>이름</th>
        <td>${item.name}</td>
        <th>나이</th>
        <td>${item.age}</td>
    </tr>
 </c:forEach>

<c:url>  url 주소 생성

 <a href="<c:url value = '/index.do' />">
<c:import>
 include 

 <c:import url="https://truecode-95.tistory.com"/>