backend
  • README
  • DOCS
    • Java Docs
    • Servlet Docs
    • JSP Docs
    • DB & SQL Docs
    • Spring Boot Docs
    • Spring Security Docs
    • AWS Docs
  • 설치하기
    • Intellij 설정
  • 자바
    • 01 Java란?
    • 02 자바 시작하기
    • 03 자료형과 연산자
    • 04 제어문
    • 05 메소드
    • 06 클래스 기초
      • Static 보충자료
      • 패키지 보충자료
    • 07 객체지향 프로그래밍
    • 08 클래스 더 알아보기
      • 열거형 ENUM 보충자료
    • 09 클래스와 자료형
      • 다형성 보충자료
      • 제네릭 보충자료
    • 10 컬렉션 프레임워크
      • 컬렉션 프레임워크 보충자료
    • 11 람다식과 함수형 프로그래밍
      • 람다식 보충자료
    • 12 오류 대비하기
      • 오류 보충자료
    • 13 멀티태스킹
      • 멀티태스킹 보충자료
    • 교재보충
      • java.lang
  • 스프링
    • 서블릿, JSP
      • 05 Servlet(서블릿)
        • 서블릿 보충자료
        • 서블릿 추가코드
        • XML, YAML, JSON
      • 06 JSP(자바 서버 페이지)
        • JSP 보충자료
      • 07 JSTL(JSP 스탠다드 태그 라이브러리)
        • JSTL 보충자료
      • 08 Cookie(쿠키), Session(세션)
      • 09 서블릿,필터,리스너
        • 서블릿,필터,리스너 보충자료
      • 11 도서관리 프로젝트 실습
    • Spring Boot
      • 01 스프링 등장 배경, 객체지향
        • 스프링 등장 배경, 객체지향 보충자료
      • 02 IOC(제어의 역전), DI(의존성 주입)
        • IOC 보충자료
        • DI 보충자료
      • 03 스프링 구조
        • 스프링 구조 보충설명
      • 04 테스트코드 실습
      • 05 스프링 빈 설정
        • 스프링 빈 설정 보충자료
      • 06 싱글톤
        • 싱글톤 보충 자료
      • 07 스프링 빈 자동설정
        • 스프링 빈 자동설정 보충자료
      • 08 빈 생명주기
        • 빈 생명주기 보충자료
      • 09 빈 스코프
        • 빈 스코프 보충자료
      • 10 스프링 MVC
        • 스프링 MVC 보충자료
        • 데이터베이스 연동에 필요한 부분
      • 11 Validation(검증)
        • Validation(검증) 보충자료
      • 12 Bean Validation(빈검증)
        • Bean Validation(빈검증) 보충자료
      • 13 예외처리
        • 예외처리 보충자료
      • 14 타입변환
      • 15 JDBC(Java Database Connectivity)
      • 16 커넥션풀
      • 17 트랜잭션
        • 트랜잭션 보충자료
      • 18 JDBC 템플릿 활용
      • 19 MyBatis
      • 20 JPA(Java Persistence API)
      • 22 게시판 프로젝트 실습
    • Spring Security
      • 보안(Security)
      • Spring Security
      • 2. Spring Security 알아보기
        • 보안 위협 실제 사례와 방어 전략
      • 3. Spring Security 기본 동작 흐름
      • 4. Spring Security로 인증 권한 추가하기
        • Spring Security의 인증 및 인가
      • 5. Spring Security에서 세션 관리하기
        • 세션(Session)과 쿠키(Cookie) 비교, 토큰(Token)과의 관계
        • 해싱 및 해싱알고리즘
        • base64
      • 6. Spring Security 악용 보호
        • SameSite
      • 7. Spring Security로 인가 권한 추가하기
      • 8. Bcrypt(비크립트) 암호화
      • OAuth2 적용하기
  • 네트워크
    • HTTP
    • OSI 7계층
  • DB&SQL
    • 01 Database(데이터베이스)와 SQL 개요
    • 02 관계형 모델
    • 03 집합
    • 04 JOIN 연산
    • 05 MySQL
      • 세이브포인트
      • DBeaver, Mysql 오토커밋 설정 관련
    • 06 SQL 기초
      • 예시데이터 쿼리문
    • 07 SQL 실습
      • 실습 스키마
    • 08 Join 활용
      • 실습스키마
    • 09 SQL 활용
      • 실습스키마
    • 10 정규화
      • 실습 스키마
    • 데이터타입
    • 예시 프로젝트 스키마 구성
  • AWS
    • SSL 연결하기
    • 보충설명
Powered by GitBook
On this page
  1. 스프링
  2. 서블릿, JSP

07 JSTL(JSP 스탠다드 태그 라이브러리)

p160 - build.gradle

plugins {
	id 'java'
	id 'war'
	id 'org.springframework.boot' version '3.2.8'
	id 'io.spring.dependency-management' version '1.1.6'
}

group = 'education'
version = '0.0.1-SNAPSHOT'

java {
	toolchain {
		languageVersion = JavaLanguageVersion.of(17)
	}
}

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
	implementation 'jakarta.servlet.jsp.jstl:jakarta.servlet.jsp.jstl-api'
	implementation 'org.glassfish.web:jakarta.servlet.jsp.jstl'
	providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
	implementation 'jakarta.servlet:jakarta.servlet-api'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
	implementation 'org.projectlombok:lombok'
	annotationProcessor 'org.projectlombok:lombok'
}

tasks.named('test') {
	useJUnitPlatform()
}

p161 - src/main/webapp/jsp/jstl/core-out.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String userName = "LEE";
    request.setAttribute("userName", userName);
%>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <p>Welcome, <c:out value="${userName}" default="Guest" /></p>
</body>
</html>

p162 - src/main/webapp/jsp/jstl/core-set.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String userName = "LEE";
    request.setAttribute("userName", userName);
%>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <c:set var="greeting" value="Hello, World!" scope="page" />
    <%-- request 스코프에서 greeting 변수를 설정 --%>
    <c:set var="greeting2" value="Hello, from Request Scope!" scope="request" />
    <%-- session 스코프에서 greeting 변수를 설정 --%>
    <c:set var="greeting3" value="Hello, from Session Scope!" scope="session" />
    <p>Message: <c:out value="${greeting}" /></p>
    <%-- application 스코프에서 greeting 변수를 설정 --%>
    <c:set var="greeting4" value="Hello, from Application Scope!" scope="application" />
</body>
</html>

p164 - src/main/webapp/jsp/jstl/core-remove.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String userName = "LEE";
    request.setAttribute("userName", userName);
%>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <c:set var="greeting" value="Hello, World!" scope="page" />
    <c:remove var="greeting" />
    <p>Message: <c:out value="${message}" default="No message found." /></p>
</body>
</html>

p165 - src/main/webapp/jsp/jstl/core-if.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>User Age Check</title>
</head>
<body>
    <%-- 나이 변수를 설정 --%>
    <c:set var="age" value="20" />

    <%-- 조건에 따라 성인 여부를 출력 --%>
    <c:if test="${age >= 18}">
        <p>You are an adult.</p>
    </c:if>
    <c:if test="${age < 18}">
        <p>You are not an adult.</p>
    </c:if>
</body>
</html>

p166 - src/main/webapp/jsp/jstl/core-choose.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>User Age Check</title>
</head>
<body>
    <%-- 나이 변수를 설정 --%>
    <c:set var="role" value="user" />
    <c:choose>
        <c:when test="${role == 'admin'}">
            <p>Welcome, Admin!</p>
        </c:when>
        <c:when test="${role == 'user'}">
            <p>Welcome, User!</p>
        </c:when>
        <c:otherwise>
            <p>Welcome, Guest!</p>
        </c:otherwise>
    </c:choose>
</body>
</html>

p168 - src/main/webapp/jsp/jstl/core-foreach.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <title>User Roles Check</title>
</head>
<body>

<%-- 역할 리스트 설정 --%>
<c:set var="roles" value="${fn:split('admin,user,guest', ',')}" />

<%-- 각 역할에 따른 메시지 출력 --%>
<c:forEach var="role" items="${roles}">
    <c:choose>
        <c:when test="${role == 'admin'}">
            <p>Welcome, Admin!</p>
        </c:when>
        <c:when test="${role == 'user'}">
            <p>Welcome, User!</p>
        </c:when>
        <c:otherwise>
            <p>Welcome, Guest!</p>
        </c:otherwise>
    </c:choose>
</c:forEach>

</body>
</html>

p169 - src/main/webapp/jsp/jstl/core-fortokens.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>User Age Check</title>
</head>
<body>
    <c:forTokens items="Java,Python,JavaScript" delims="," var="language">
        <p>${language}</p>
    </c:forTokens>
</body>
</html>

p170 - src/main/webapp/jsp/jstl/core-import.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!-- 헤더 포함 -->
<c:import url="header.jsp" />
<!-- 메인 콘텐츠 -->
<p>This is the main content of the page.</p>
<!-- 푸터 포함 -->
<c:import url="footer.jsp" />

p171 - src/main/webapp/jsp/jstl/core-url.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>User Age Check</title>
</head>
<body>
    <%-- 나이 변수를 설정 --%>
    <c:set var="id" value="3" />
    <c:url value="/profile" var="profileUrl">
        <c:param name="userId" value="${id}" />
    </c:url>

    <a href="${profileUrl}">View Profile</a>
</body>
</html>

p173 - src/main/webapp/jsp/jstl/fmt.jsp

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  java.util.Date now = new java.util.Date();
  request.setAttribute("now", now);
%>
<%
  double amount = 1234567.89;
  request.setAttribute("amount", amount);
%>


<p>Current Date and Time:</p>

<!-- 날짜만 포맷 -->
<fmt:formatDate value="${now}" pattern="yyyy-MM-dd" />
<br>
<!-- 시간만 포맷 -->
<fmt:formatDate value="${now}" type="time" timeStyle="short" />
<br>
<!-- 날짜와 시간 모두 포맷 -->
<fmt:formatDate value="${now}" type="both" dateStyle="long" timeStyle="short" />
<br>

<p>Original Number: ${amount}</p>
<!-- 숫자 포맷 -->
<p>Formatted Number: <fmt:formatNumber value="${amount}" /></p>
<!-- 통화 포맷 -->
<p>Formatted Currency: <fmt:formatNumber value="${amount}" type="currency" /></p>
<!-- 백분율 포맷 -->
<p>Formatted Percentage: <fmt:formatNumber value="0.85" type="percent" /></p>
<!-- 사용자 정의 패턴 포맷 -->
<p>Custom Pattern: <fmt:formatNumber value="${amount}" pattern="#,###.00" /></p>


<!-- 로케일을 미국으로 설정 -->
<fmt:setLocale value="en_US" />
<p>Current Locale is set to US</p>
<!-- 로케일을 한국으로 설정 -->
<fmt:setLocale value="ko_KR" />
<p>Current Locale is set to Korea</p>

p174, 176 - src/main/webapp/jsp/jstl/fmt-messages.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!-- 로케일을 한국어로 설정 -->
<%--<fmt:setLocale value="ko_KR" />--%>
<%--<fmt:setLocale value="en_US" />--%>
<%--<fmt:setLocale value="${header['Accept-Language']}" />--%>

<!-- 메시지 번들 설정 -->
<fmt:setBundle basename="messages" />

<!-- 로케일에 맞는 메시지 출력 -->
<p><fmt:message key="greeting" /></p>
<p><fmt:message key="farewell" /></p>
<p>Browser Accept-Language: ${header['Accept-Language']}</p>

p178 - src/main/webapp/jsp/jstl/fn.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!-- 문자열 길이 확인 -->
<p>Length of 'Hello World': ${fn:length('Hello World')}</p>

<!-- 문자열 포함 여부 확인 -->
<c:if test="${fn:contains('Hello World', 'World')}">
    <p>'World' is found in 'Hello World'.</p>
</c:if>

<!-- 배열을 문자열로 결합 -->
<%
    String[] words = {"Hello", "World", "JSTL"};
    request.setAttribute("words", words);
%>
<p>Joined String: ${fn:join(words, ', ')}</p>

<!-- 부분 문자열 추출 -->
<p>Substring of 'Hello World': ${fn:substring('Hello World', 0, 5)}</p>

PreviousJSP 보충자료NextJSTL 보충자료

Last updated 6 months ago