JSP의 경우 HTML 태그와 같이 사용되어 전체적인 코드의 가독성이 떨어진다.

이러한 단점을 보완하고저 만들어진 태그가 JSTL이다.

JSTL의 경우 우리가 사용하는 Tomcat 컨테이너에 포함되어 있지 않으므로 , 별도의 설치가 필요하다.

 

 

의존성 설정

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

 

 

<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>

 

설치

jakarta.apache.org/

 

The Jakarta Site - The Apache Jakarta™ Project -- Java Related Products

Founded in 1999, the Jakarta Project housed a diverse set of popular open source Java solutions. In 2005, as a part of creating a flatter Apache Software Foundation, Jakarta subprojects began to become full top-level Apache projects. This process has conti

jakarta.apache.org

 

Taglibs 클릭

 

다운로드

 

JSTL 라이브러리

lib URI Prefix ex
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 라이브러리

Core 라이브러리는 기본적인 라이브러리로 출력, 제어문, 반복문 같은 기능이 포함되어 있다.

 

 

사용

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

 

 

출력 태그 : <c:out>

<c:out value="출력값" default="기본값" escapeXml ="true or false">

 

변수 설정 태그 <c:set>

<c:set var="변수명" value="설정값" target="객체" property="값" scope="범위">

 

변수를 제거하는 태그 <c:remove>

<c:remove var="변수명" scope="범위">

 

예외 처리 태그 <c:catch>

<c:catch var="변수명">

 

제어문(if) 태그 <c:if>

<c:if test="조건" var="조건 처리 변수명" scope="범위">

 

ex)detail.jsp

<c:if test="${board.user.id == principal.user.id}">
  <a href="/board/${board.id}/updateform" class="btn btn-primary">수정</a>
  <button id="btn-delete" class="btn btn-danger">삭제</button>
  </c:if>

 

제어문(swich) 태그 <c:choose>

 

<c:choose>
<c:when test="조건">처리 내용 </c:when>
<c:otherwise> 처리 내용 </c:otherwise>
</c:choose>

 

반복문 (for) 태그 <c:forEach>

<c:forEach items="객체명" begin="시작 인덱스" end="끝 인덱스" step="증감식"
var="변수명" varStatus="상태변수">

 

ex) detail.jsp

	<ul id="reply--box" class="list-group">
 		<c:forEach var="reply" items="${board.reply }">
 		<li id="reply--1" class="list-group-item d-flex justify-content-between">
             <div>${reply.content}</div>
             <div class="d-flex">
              <div class ="font-italic">작성자 : ${reply.user.username} &nbsp: </div>
              <button class="badge">삭제</button>
             </div>
 		</li>
 		</c:forEach>

 

페이지 이동 태그  <c:redirect>

<c:redirect url="url">

 

파라미터 전달 태그 <c:param>

 

<c:param name="파라미터명" value="값" >

 

www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm

 

JSP - Standard Tag Library (JSTL) Tutorial - Tutorialspoint

JSP - Standard Tag Library (JSTL) Tutorial In this chapter, we will understand the different tags in JSP. The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates the core functionality common to many JSP appli

www.tutorialspoint.com

 

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

jsp 파일에 붙여넣기

 

 

 

의존성 설정

<!-- JSTL -->
<dependency>
 	<groupId>javax.servlet</groupId>
	<artifactId>jstl</artifactId>
</dependency>

 

 


※  그 전에 JSP 파일을 스프링 부트에서 사용하려면

 

<!-- JSP 템플릿 엔진 -->
		 	
		 <dependency>
		  <groupId>org.apache.tomcat.embed</groupId>
		  <artifactId>tomcat-embed-jasper</artifactId>
		</dependency>

+ Recent posts