본문 바로가기
IT/JSP

[JSP] - 33. JSTL(JSP Standard Tag Library) 사용 방법

by 차이나는 개발자 2020. 8. 10.
728x90
반응형

#JSTL(JSP Standard Tag Library) 사용 방법

 

 

#Maven

라이브러리 다운로드하기

https://mvnrepository.com/artifact/javax.servlet/jstl

 

Maven Repository: javax.servlet » jstl

Professional Java Data: RDBMS, JDBC, SQLJ, OODBMS, JNDI, LDAP, Servlets, JSP, WAP, XML, EJBs, CMP2.0, JDO, Transactions, Performance, Scalability, Object and Data Modeling (2001)by Carl Calvert Bettis, Michael Bogovich, Sean Rhody, Mark Wilcox, Kelly Lin P

mvnrepository.com

 

 

#사용량이 많은 1.2.x 버전 클릭해서 다운로드

 

 

#jar파일 다운

 

 

#프로젝트 WEbContent -> lib폴더에 추가

 

 

#jsp페이지 상단에 태그 라이브러리 선언해서 사용

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

 

 

#데이터 제어

#태그 라이브러리의 표준화

Core

<c:out>

<c:remove>

<c:choose>

<c:otherwise>

<c:forEach>

<c:param>

<c:url>

<c:set>

<c:if>

<c:when>

<c:import>

<c:forTokens>

<c:redirect>

<c:catch>

Formating

Functions

SQL

XML

 

 

예제 1)

 

 

1. jstl.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>    
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<%
		int num = 3; // 지역변수 (속성X)
	%>
	<!-- 변수(속성) 설정 -->
	<c:set var="num" value="100" />
	
	<!-- 변수(속성) 제거 -->
	<%-- <c:remove var="num"/> --%>
	${num }
	
	<!-- 조건문 -->
	<c:if test="${num > 5 }">
		hi~
	</c:if>
	<hr>
      <c:choose>
         <c:when test = "${num < 50}">
           	 50보다 적습니다.
         </c:when>
         <c:when test = "${num > 50}">
           	 50보다 큽니다.
         </c:when>
         <c:otherwise>
           	 그렇다.
         </c:otherwise>
      </c:choose>
	
	<!-- 반복문 -->
	<c:forEach var="i" begin="0" end="10" step="3">
		${i }<br>
	</c:forEach>
	
	<%
	ArrayList<String> list = new ArrayList<String>();
	list.add("a");
	list.add("b");
	list.add("c");
	list.add("d");
	list.add("e");
	list.add("f");
	
	pageContext.setAttribute("list", list);
	%>
	<hr>
	<c:forEach var="word" items="${ list }">
		${ word }
	</c:forEach>
	<hr>
	<c:forEach var="num" begin="0" end="5" varStatus="status">
		begin : ${status.begin }<br>
		end : ${status.end }<br>
		current : ${status.current }<br>
		count : ${status.count }<br>
		<hr> 
	</c:forEach>
</body>
</html>

 

 

 

728x90
반응형

댓글