[JSP] EL / JSTL


EL (Expression Language)


  • ํ‘œํ˜„์‹ ๋˜๋Š” ์•ก์…˜ํƒœ๊ทธ๋ฅผ ํŽธ๋ฆฌํ•˜๊ฒŒ ์ถœ๋ ฅํ•˜๊ธฐ ์œ„ํ•œ ์–ธ์–ด

  • ex) ${ }

    • <%=value %> -> ${value}

    • <jsp:getProperty name="member" property="name" /> -> ${member.name}

    => ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ๊ณผ ์ ˆ์•ฝ์„ฑ โ†‘

  • EL ๋‚ด์žฅ๊ฐ์ฒด

    • pageScope : page Scope ์ฐธ์กฐ

      • Scope๋ž€? ์›น ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ƒ์„ฑ๋œ ๋ณ€์ˆ˜ ๋˜๋Š” ๊ฐ์ฒด๊ฐ€ ์œ ํšจํ•œ ๋ฒ”์œ„

      • page scope = page ์˜์—ญ์˜ ๊ฐ์ฒด

    • requestScope : request Scope ์ฐธ์กฐ

    • sessionScope : session Scope ์ฐธ์กฐ

    • applicationScope : application Scope ์ฐธ์กฐ

    • param : ์š”์ฒญ ํŒŒ๋ผ๋ฏธํ„ฐ ์ฐธ์กฐ (1๊ฐœ์˜ key - 1๊ฐœ์˜ value)

    • paramValues : ์š”์ฒญ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ฐฐ์—ด๋กœ ์ฐธ์กฐ (1๊ฐœ์˜ key - ์—ฌ๋Ÿฌ๊ฐœ์˜ value)

    • initParam : ์ดˆ๊ธฐํ™” ํŒŒ๋ผ๋ฏธํ„ฐ ์ฐธ์กฐ

    • cookie : cookie ๊ฐ์ฒด ์ฐธ์กฐ



JSTL (JSP Standard Tag Library)


  • JSP๋Š” HTML ํƒœ๊ทธ์™€ Java ๋ฌธ๋ฒ•์„ ๊ฐ™์ด ์‚ฌ์šฉํ•ด ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ์ด ๋–จ์–ด์ง€๋Š”๋ฐ, JSTL์€ ์ด๋Ÿฌํ•œ ๋‹จ์ ์„ ๋ณด์™„ํ•˜๊ณ ์ž ๋งŒ๋“ค์–ด์ง„ ํƒœ๊ทธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ด๋‹ค.

  • JSTL์„ ์‚ฌ์šฉํ•จ์œผ๋กœ์จ Java ์ฝ”๋“œ๋ฅผ ์—†์• ๊ณ  ํƒœ๊ทธ ํ˜•ํƒœ๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ์Œ

  • JSTL์€ ํ†ฐ์บฃ ์ปจํ…Œ์ด๋„ˆ์— ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์œผ๋ฏ€๋กœ ๋”ฐ๋กœ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค.

    https://tomcat.apache.org/taglibs/standard/

  • JSTL ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ : Core, XML, Processiong, I18N, Database, Functions

    • ํƒœ๊ทธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ ์–ธ : <%@ taglib prefix="์ ‘๋‘์‚ฌ" uri="URI" %>

    • Core

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

      • ๋ณ€์ˆ˜ ์„ ์–ธ, ์‹คํ–‰ ํ๋ฆ„ ์ œ์–ด, URL ๊ด€๋ฆฌ

    • XML

      • <%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>

      • XML๋ฌธ์„œ๋ฅผ ์ฒ˜๋ฆฌํ•  ๋•Œ ํ•„์š”ํ•œ ๊ธฐ๋Šฅ ์ œ๊ณต, ํ๋ฆ„ ์ œ์–ด, ๋ณ€ํ™˜

    • Formatting, I18N

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

      • ์ˆซ์ž ๋‚ ์งœ ์‹œ๊ฐ„ ํฌ๋งคํŒ…, ๊ตญ์ œํ™”, ๋‹ค๊ตญ์–ด ์ง€์›

    • Database

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

      • DB์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ž…๋ ฅ, ์ˆ˜์ •, ์‚ญ์ œ, ์กฐํšŒํ•˜๋Š” ๊ธฐ๋Šฅ ์ œ๊ณต

    • Functions

      • <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

      • ๋ฌธ์ž์—ด ์กฐ์ž‘, ๋งต/์ปฌ๋ ‰์…˜์˜ ๊ฐ€๊ณต, ๋ณ€ํ™˜, ๋ถ„์„

  • Core ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

    • ์ถœ๋ ฅ, ์ œ์–ด๋ฌธ, ๋ฐ˜๋ณต๋ฌธ ๋“ฑ์˜ ๊ธฐ๋Šฅ ํฌํ•จ

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

      • ์ถœ๋ ฅ ํƒœ๊ทธ : <c:out>

      • ๋ณ€์ˆ˜ ์„ค์ • ํƒœ๊ทธ : <c:set>

      • ๋ณ€์ˆ˜ ์ œ๊ฑฐ ํƒœ๊ทธ : <c:remove>

      • ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ํƒœ๊ทธ : <c:catch>

      • ์ œ์–ด๋ฌธ ํƒœ๊ทธ - if : <c:if>

      • ์ œ์–ด๋ฌธ ํƒœ๊ทธ - switch : <c:choose>

      • ๋ฐ˜๋ณต๋ฌธ ํƒœ๊ทธ - for : <c:forEach>

      • ํŽ˜์ด์ง€ ์ด๋™ ํƒœ๊ทธ : <c:redirect>

      • ํŒŒ๋ผ๋ฏธํ„ฐ ์ „๋‹ฌ ํƒœ๊ทธ : <c:param>

Categories:

JSP/Servlet