728x90
JSP에서는 사용자가 필요하면 tag를 자체적으로 만들어 사용할 수 있다. Apache에서는 메우 유용한 커스텀 태그를 제공하고 이 것을 JSTL이라 한다.
⚙️ 환경설정
프로젝트의 WEB-INF/lib 폴더에 jstl.jar
standard.jar
파일 추가

제공 라이브러리
라이브러리 | URI | Prefix | |
---|---|---|---|
Core | http://java.sun.com/jsp/jstl/core | c | <c:tag ... > |
XML Processing | http://java.sun.com/jsp/jstl/xml | x | <x:tag ... > |
I18N formatting | http://java.sun.com/jsp/jstl/fmt | fmt | <fmt:tag ... > |
SQL | http://java.sun.com/jsp/jstl/sql | sql | <sql:tag ... > |
Functions | http://java.sun.com/jsp/jstl/functions | fn | fn.function(...) |
주로 Core 라이브러리 이용. 라이브러리 이용 시 아래 코드 필수로 작성
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefiex="c" %>
JSTL Core 라이브러리
태그 | 설명 |
---|---|
<c:if> | 조건 처리할 때 사용 |
<c:forEach> | 반복 처리할 때 사용 |
<c:choose> <c:when> <c:otherwise> | 자바의 switch문과 비슷 |
<c:out> | 지정된 값 출력 |
<c:set> | scope에 따른 데이터 저장/조회 가능 |
<c:remove> | scope에 따른 속성 제거 가능 |
<c:url> | URL을 생성 |
<c:forTokens> | 자바의 StringTokenzier 클래스 기능 |
⌛️ 조건문 예시
<c:if test="${userid=='옥지얌'}">
옥지 이다.
</c:if>
<c:if test="${userid!='옥지얌'}">
옥지가 아니다.
</c:if>
<c:choose>
<c:when test="${userid=='옥지얌'}">
옥지 이다.
</c:when>
<c:when test="${userid=='빵빵아'}">
빵빵이 이다.
</c:when>
<c:otherwise>
모르는 사람이다.
</c:otherwise>
</c:choose>
⌛️ 반복문 예시
1. range 반복
<c:forEach var="x" begin="1" end="10" step="2">
${x}. HELLO<br>
</c:forEach>
2. list 반복
<c:forEach var="dto" items="${list}" varStatus="status">
${status.index}. ${dto.userid} 개수:${status.count} <br>
</c:forEach>
⌛️ URL 예시
<a href="<c:url value='JSTLServlet'/>">JSTLServlet</a> <br>
728x90
'WebServer > JSP&Servlet' 카테고리의 다른 글
[JSP&Servlet] EL (Expression Language) (0) | 2023.08.24 |
---|---|
[JSP&Servlet] JSP 태그 (0) | 2023.08.21 |
[JSP&Servlet] 파일 업로드 (File upload) (0) | 2023.08.21 |
[JSP&Servlet] 쿠키를 이용한 간단한 로그인&로그아웃 (0) | 2023.08.21 |
[JSP&Servlet] 세션을 활용한 간단한 로그인&로그아웃 (0) | 2023.08.21 |
728x90
JSP에서는 사용자가 필요하면 tag를 자체적으로 만들어 사용할 수 있다. Apache에서는 메우 유용한 커스텀 태그를 제공하고 이 것을 JSTL이라 한다.
⚙️ 환경설정
프로젝트의 WEB-INF/lib 폴더에 jstl.jar
standard.jar
파일 추가

제공 라이브러리
라이브러리 | URI | Prefix | |
---|---|---|---|
Core | http://java.sun.com/jsp/jstl/core | c | <c:tag ... > |
XML Processing | http://java.sun.com/jsp/jstl/xml | x | <x:tag ... > |
I18N formatting | http://java.sun.com/jsp/jstl/fmt | fmt | <fmt:tag ... > |
SQL | http://java.sun.com/jsp/jstl/sql | sql | <sql:tag ... > |
Functions | http://java.sun.com/jsp/jstl/functions | fn | fn.function(...) |
주로 Core 라이브러리 이용. 라이브러리 이용 시 아래 코드 필수로 작성
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefiex="c" %>
JSTL Core 라이브러리
태그 | 설명 |
---|---|
<c:if> | 조건 처리할 때 사용 |
<c:forEach> | 반복 처리할 때 사용 |
<c:choose> <c:when> <c:otherwise> | 자바의 switch문과 비슷 |
<c:out> | 지정된 값 출력 |
<c:set> | scope에 따른 데이터 저장/조회 가능 |
<c:remove> | scope에 따른 속성 제거 가능 |
<c:url> | URL을 생성 |
<c:forTokens> | 자바의 StringTokenzier 클래스 기능 |
⌛️ 조건문 예시
<c:if test="${userid=='옥지얌'}">
옥지 이다.
</c:if>
<c:if test="${userid!='옥지얌'}">
옥지가 아니다.
</c:if>
<c:choose>
<c:when test="${userid=='옥지얌'}">
옥지 이다.
</c:when>
<c:when test="${userid=='빵빵아'}">
빵빵이 이다.
</c:when>
<c:otherwise>
모르는 사람이다.
</c:otherwise>
</c:choose>
⌛️ 반복문 예시
1. range 반복
<c:forEach var="x" begin="1" end="10" step="2">
${x}. HELLO<br>
</c:forEach>
2. list 반복
<c:forEach var="dto" items="${list}" varStatus="status">
${status.index}. ${dto.userid} 개수:${status.count} <br>
</c:forEach>
⌛️ URL 예시
<a href="<c:url value='JSTLServlet'/>">JSTLServlet</a> <br>
728x90
'WebServer > JSP&Servlet' 카테고리의 다른 글
[JSP&Servlet] EL (Expression Language) (0) | 2023.08.24 |
---|---|
[JSP&Servlet] JSP 태그 (0) | 2023.08.21 |
[JSP&Servlet] 파일 업로드 (File upload) (0) | 2023.08.21 |
[JSP&Servlet] 쿠키를 이용한 간단한 로그인&로그아웃 (0) | 2023.08.21 |
[JSP&Servlet] 세션을 활용한 간단한 로그인&로그아웃 (0) | 2023.08.21 |