๐ท JSP 2.3 & Servlet3.1 - JSTL๊ณผEL : core,format,function,el,custom tag EL
โ JSTL core : out
- <c:out> : ์ถ๋ ฅ
- JSTL core(out)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ page import = "java.io.IOException, java.io.FileReader" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title><c:out></title> </head> <body> <!-- xml ํ๊ทธ ๋ฐ & ํน์๋ฌธ ์ ํ๊ธฐ์์์ ์ฐจ์ด --> <c:set var="temp" value="JSTL & EL, <tag> " /> <!-- ๋ง์ฝ 2), 3)์ ๊ฒฝ์ฐ์์ ํ๊ทธ๊ฐ ์ ๋๋ก ๋์ค๋ ค๋ฉด ์๋์ ๊ตฌ๋ฌธ์ผ๋ก ๊ต์ฒดํฉ๋๋ค. --> <!--<c:set var="temp" value="JSTL & EL, <tag> " /> --> <!-- escapeXml= "" : escape๋ฌธ์ ์ฒ๋ฆฌ์ฌ๋ถ ํ๊ธฐ true : escape๋ฌธ์ ํด์ X, flase : escape ๋ฌธ์ ํด์ O--> 1) escapeXml="true" : <c:out value="${temp}" escapeXml="true" /><br> 2) escapeXml="false" : <c:out value="${temp}" escapeXml="false" /><br> 3) EL : ${temp} </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL core : url,param
- <c:url> : URL ๋งํฌ
- <c:param> : ์ธ์ ์ ๋ฌ
- JSTL core(url,param)
<%@ page contentType="text/html; charset=UTF-8" session="false" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> </head> <body> <!-- c:url value="http://search.daum.net/search" : ์ ๋๊ฒฝ๋ก ์ฐพ๊ธฐ ํธ๋ฆฌํ๋๋ก ํ๊ฒ --> context Path(๊ฒฝ๋ก) : ${pageContext.request.contextPath}<br> context Path(๊ฒฝ๋ก) : <%=request.getContextPath() %> <c:url value="http://search.daum.net/search" var="searchUrl"> <c:param name="w" value="blog" /> <c:param name="q" value="๊ณต์" /> </c:url> <ul> <li><a href="${searchUrl}">๋งํฌ1</a></li> <!-- /๊ฒฝ๋ก์ ./๊ฒฝ๋ก์ ์ฐจ์ด / : ํ์ฌ๊ฒฝ๋ก(jstl)๋ฅผ ์๋ตํ๊ธฐ ๋๋ฌธ์ ์ค๋ฅ๊ฐ ๋๋ค --> <li><a href="<c:url value="/use_if_tag.jsp" />">๋งํฌ2</a></li> <li><a href="<c:url value="./use_if_tag.jsp" />">๋งํฌ3</a></li> </ul> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL core : if
- <c:if> : ์กฐ๊ฑด๋ฌธ
- JSTL core(if)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>if ํ๊ทธ</title> </head> <body> <c:if test="true"> ๋ฌด์กฐ๊ฑด ์ํ<br> </c:if> <!-- ์๋(EL)์ ๊ฐ์ํํ ์ด์ง๋ง ์ฌ์ฉ X --> <!--<c:if test='<%=request.getParameter("name").equals("bk") %>'>--> <!--์ ์กฐ๊ฑด ํด๋น๋๋ฉด ์กฐ๊ฑด๋ฌธ์ ๋น ์ ธ๋๊ฐ๋ค--> <c:if test="${param.name == 'bk'}"> name ํ๋ผ๋ฏธํฐ์ ๊ฐ์ด ${param.name} ์ ๋๋ค.<br> </c:if> age : ${param.age }<br> <c:if test='<%=Integer.parseInt(request.getParameter("age")) > 18 %>'> <!-- <c:if test="${18 < param.age}">--> ๋น์ ์ ๋์ด๋ 18์ธ ์ด์์ ๋๋ค. </c:if> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL core : choose,when,otherwise
- <c:choose> : ์กฐ๊ฑด๋ฌธ
- <c:when> : ์กฐ๊ฑด๋ฌธ
- <c:otherwise> : ์กฐ๊ฑด๋ฌธ
- if,else if์ ๊ฐ๋ค
- JSTL core(choose,when,otherwise)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>choose ํ๊ทธ</title> </head> <body> <ul> <c:choose> <!-- ์ ์กฐ๊ฑด ํด๋น๋๋ฉด ์กฐ๊ฑด๋ฌธ์ ๋น ์ ธ๋๊ฐ๋ค --> <c:when test="${param.name == 'bk'}" > <li> ๋น์ ์ ์ด๋ฆ์ ${param.name} ์ ๋๋ค.</li> </c:when> <c:when test="${param.age >= 20}" > <li> ๋น์ ์ 20์ธ ์ด์์ ๋๋ค.</li> </c:when> <c:otherwise> <li> ๋น์ ์ 'bk'๊ฐ ์๋๊ณ 20์ธ ์ด์์ด ์๋๋๋ค.</li> </c:otherwise> </c:choose> </ul> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL core : catch
- <c:catch> : ์์ธ์ฒ๋ฆฌ
- JSTL core(catch)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>catch ํ๊ทธ</title> </head> <body> <c:catch var="ex"> name ํ๋ผ๋ฏธํฐ์ ๊ฐ = <%= request.getParameter("name") %><br> <% if (request.getParameter("name").equals("test")) { %> ${param.name}์ test ์ ๋๋ค. <% } %> </c:catch> <p> <!-- ๋๊ฐ์ง ๋ค ๊ฐ์๊ฒฐ๊ณผ ๋์ถ --> <!-- <c:if test = "${not empty ex }" > --> <c:if test="${ex != null}"> ์์ธ๊ฐ ๋ฐ์ํ์์ต๋๋ค:<br> ${ex} </c:if> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL core : forEach
- <c:forEach> : ๋ฐ๋ณต๋ฌธ
- JSTL core(forEach)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ page import="java.util.HashMap" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% HashMap<String,Object> mapData = new HashMap<String,Object>(); mapData.put("name", "JSP"); mapData.put("today", new java.util.Date()); %> <c:set var="intArray" value="<%= new int[] {1,2,3,4,5} %>" /> <c:set var="map" value="<%= mapData %>" /> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>forEach ํ๊ทธ</title> </head> <body> <h4>1๋ถํฐ 100๊น์ง ํ์์ ํฉ</h4> <c:set var="sum" value="0" /> <!-- begin, end ๊ผญ ์์จ๋ ๋๋ค --> <c:forEach var="i" begin="1" end="100" step="2"> <!-- c:set ๋ ์ฌ์ฉํ๋ฉด ์ฌ์ ์ ๋๋ค , ์ฌ์ฉ๊ฐ๋ฅํ๋ค --> <c:set var="sum" value="${sum + i}" /> </c:forEach> ๊ฒฐ๊ณผ = ${sum} <h4>๊ตฌ๊ตฌ๋จ: 4๋จ</h4> <ul> <c:forEach var="i" begin="1" end="9"> <li>4 * ${i} = ${4 * i} </c:forEach> </ul> <h4>intํ ๋ฐฐ์ด</h4> <c:forEach var="i" items="${intArray}" begin="2" end="4" varStatus="status"> ${status.index}-${status.count}-[${i}] <br /> </c:forEach> <h4>Map</h4> <c:forEach var="i" items="${map}"> ${i.key} = ${i.value}<br> </c:forEach> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL core : forTokens
- <c:forTokens> : ๋ฌธ์์ด ๋ถํ
- JSTL core(forTokens)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>forTokens ํ๊ทธ</title> </head> <body> ์ฝค๋ง์ ์ ์ ๊ตฌ๋ถ์๋ก ์ฌ์ฉ:<br> <c:forTokens var="token" items="๋นจ๊ฐ์,์ฃผํฉ์.๋ ธ๋์.์ด๋ก์,ํ๋์,๋จ์.๋ณด๋ผ์" delims=",."> <!-- token ๋ค์ <br> ์ฝ์ ์ ๋จ์ด๋ง๋ค br์ ์ฉ๋๋ค --> ${token}<br> </c:forTokens> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL core : import
- <c:import> : ํ์ด์ง ์ฝ์
- JSTL core(import)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% request.setCharacterEncoding("UTF-8"); %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>ํ์ด์ง ์ฝ์ : <c:import></title> </head> <body> <p style="background:cyan">ํ์ด์ง(์๋จ)</p> <hr> <c:import url="https://search.naver.com/search.naver"> <!-- <c:param name="" value="" /> : ์ฟผ๋ฆฌ๊ฐ : ์ url๋ค์ ?๋ค์ ๋ฐ์์ค๋ ์ธ์๊ฐ๋ค--> <c:param name="sm" value="top_hty" /> <c:param name="fbm" value="0" /> <c:param name="ie" value="utf8" /> <c:param name="query" value="์์ธ์ฒ" /> </c:import> <hr> <p style="background:pink">ํ์ด์ง(ํ๋จ)</p> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL core : redirect
- <c:redirect> : ํ์ด์ง ์ด๋
- JSTL core(redirect)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>ํ์ด์ง ์ด๋</title> </head> <body> <c:redirect url="https://search.naver.com/search.naver"> <c:param name="sm" value="top_hty" /> <c:param name="fbm" value="0" /> <c:param name="ie" value="utf8" /> <c:param name="query" value="์์ธ์ฒ" /> </c:redirect> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL format
- ๊ตญ์ ํ(๋ค๊ตญ์ด ์ฒ๋ฆฌ)/ ํ์ํ(๋ ์ง์ ์ซ์ ํ์ ์ฒ๋ฆฌ)์ ๊ธฐ๋ฅ์ ์ ๊ณตํด์ฃผ๋ JSTL ๋ผ์ด๋ธ๋ฌ๋ฆฌ
- core ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ง์ฐฌ๊ฐ์ง๋ก JSP ํ์ด์ง์ ํ๊ทธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ฑ๋กํด์ผ ์ฌ์ฉ๊ฐ๋ฅ
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
โ JSTL format : formatDate
- <fmt:formatDate> : ๋ ์ง ํฌ๋งท
- JSTL core(formatDate)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>dateFormat ํ๊ทธ ์ฌ์ฉ</title> </head> <body> <c:set var="now" value="<%= new java.util.Date() %>" /> <fmt:formatDate value="${now}" type="date" dateStyle="full" /> <br> <fmt:formatDate value="${now}" type="date" dateStyle="short" /> <br> <fmt:formatDate value="${now}" type="time" /> <br> <fmt:formatDate value="${now}" type="both" dateStyle="full" timeStyle="full" /> <br> <fmt:formatDate value="${now}" pattern="z a h:mm" /> <br> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL format : setLocale
- <fmt:setLocale> : ์ธ๊ณ ์ง์ญ
- JSTL core(setLocale)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>numberFormat ํ๊ทธ ์ฌ์ฉ</title> </head> <body> <!-- ์ธ์ด ๋ถ๋ฅ ํ์คํ ๋ช ๋ช => ISO-639 : https://ko.wikipedia.org/wiki/ISO_639-1_%EC%BD%94%EB%93%9C_%EB%AA%A9%EB%A1%9D --> <!-- ์ธ๊ณ์ ๋๋ผ์ ๋ถ์ ์ํ , ๊ตญ๊ฐ์ ์ฃผ์ ๊ตฌ์ฑ ๋จ์์ ๋ช ์นญ์ ๊ณ ์ ๋ถํธ => ISO-3166-1 : https://ko.wikipedia.org/wiki/ISO_3166-1 --> <!-- locale value : ISO-639 + "_" + ISO-3166-1 --> ํ๊ตญ : <fmt:setLocale value="ko_kr"/> ๊ธ์ก(์(ๅ)) : <fmt:formatNumber value="100000" type="currency" /><br> ๋ฏธ๊ตญ : <fmt:setLocale value="en_us"/> ๊ธ์ก (๋ฌ๋ฌ): <fmt:formatNumber value="100000" type="currency" /><br> ํ๋์ค : <fmt:setLocale value="fr_fr"/> ๊ธ์ก (์ ๋ก) : <fmt:formatNumber value="100000" type="currency" /><br> ์๊ตญ : <fmt:setLocale value="en_gb"/> ๊ธ์ก(ํ์ด๋) : <fmt:formatNumber value="100000" type="currency" /><br> ์ค๊ตญ : <fmt:setLocale value="zh_cn"/> ๊ธ์ก(์์,ๅ ) : <fmt:formatNumber value="100000" type="currency" /><br> ์ผ๋ณธ : <fmt:setLocale value="ja_jp"/> ๊ธ์ก (์,ๅ(ๅ)): <fmt:formatNumber value="100000" type="currency" /><br> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL format : timeZone
- <fmt:timeZone> : ์๊ฐ๋
- JSTL core(timeZone)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>์๊ฐ๋ ๋ชฉ๋ก</title> </head> <body> <c:forEach var="id" items="<%= java.util.TimeZone.getAvailableIDs() %>"> ${id}<br /> </c:forEach> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL format : bundle , message
- <fmt:bundle> : ๋ฉ์์ง
- <fmt:message> : ๋ฉ์์ง
- JSTL core(bundle , message) ํ
์คํธ properties
name=\ud64d\uae38\ub3d9. say=\uc548\ub155\ud558\uc138\uc694 \ud64d\uae38\ub3d9\uc785\ub2c8\ub2e4. say2=\ub0b4 \uce5c\uad6c\ub294 {0} \uc785\ub2c8\ub2e4.
- jsp ์ฝ๋
<%@ page language="java" contentType="text/html; charset=UTF-8"%> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <jsp:useBean id="date" class="java.util.Date"/> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>JSTL fmt ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฌ์ฉ ์์ </title> </head> <body> <%-- <fmt:setLocale value="en_US"/> --%> <fmt:setLocale value="ko_KR"/> <!-- ๊ธฐ๋ณธ์ ์ผ๋ก basename์ test.properties ๋ฉ์์ง ํ์ผ์ ์๋ฏธํฉ๋๋ค. locale(๊ตญ์ ํ) ์ ๋ณด์ ๋ฐ๋ผ ํ๊ตญ์ด๋ฉด test_ko.properties๋ฅผ ๊ฒ์ํ๊ณ ๋ฏธ๊ตญ์ด๋ฉด test_en.properties๋ฅผ ๊ฒ์ํฉ๋๋ค. ๋ง์ฝ test_en.properties์ด ์๋ค๋ฉด test_en.properties์์ ๋ฉ์์ง๋ฅผ ๊ฒ์ํฉ๋๋ค. ํ์ผ์ ์๋ฐ ์์ค๊ฐ ๋ค์ด๊ฐ๋ ํจํค์ง(package)์ ์์น์ํต๋๋ค.--> <fmt:bundle basename="msg.test"> <fmt:message key="name"/><br> <fmt:message key="say"/><br> <fmt:message key="say2"> <fmt:param value="๊ณ ๊ธธ๋"/> </fmt:message> </fmt:bundle> <p> <fmt:formatNumber value="50000" type="currency"/><br> <fmt:formatNumber value="0.15" type="percent"/><br> <fmt:formatNumber value="500567300" pattern="###,###,###"/><p> <fmt:formatDate value="${date}" type="date"/><br> <fmt:formatDate value="${date}" type="time"/><br> <fmt:formatDate value="${date}" type="both"/><p> <fmt:formatDate value="${date}" type="both" timeStyle="short" dateStyle="short"/><br> <fmt:formatDate value="${date}" type="both" timeStyle="long" dateStyle="long"/><br> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL format : formatNumber
- <fmt:formatNumber> : ์ซ์ ํฌ๋งท
- JSTL core(formatNumber)- 1
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>numberFormat ํ๊ทธ ์ฌ์ฉ</title> </head> <body> <c:set var="price" value="10000" /> <fmt:formatNumber value="${price}" type="number" var="numberType" /><br> ํตํ : <fmt:formatNumber value="${price}" type="currency" currencySymbol="์" /><br> ํผ์ผํธ : <fmt:formatNumber value="${price}" type="percent" groupingUsed="false" /><br> ์ซ์ : ${numberType}<br> ํจํด : <fmt:formatNumber value="${price}" pattern="00000000.00"/> </body> </html>
- JSTL core(formatNumber)- 2
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>numberFormat ํ๊ทธ ์ฌ์ฉ</title> </head> <body> <!-- ์ธ์ด ๋ถ๋ฅ ํ์คํ ๋ช ๋ช => ISO-639 : https://ko.wikipedia.org/wiki/ISO_639-1_%EC%BD%94%EB%93%9C_%EB%AA%A9%EB%A1%9D --> <!-- ์ธ๊ณ์ ๋๋ผ์ ๋ถ์ ์ํ , ๊ตญ๊ฐ์ ์ฃผ์ ๊ตฌ์ฑ ๋จ์์ ๋ช ์นญ์ ๊ณ ์ ๋ถํธ => ISO-3166-1 : https://ko.wikipedia.org/wiki/ISO_3166-1 --> <!-- locale value : ISO-639 + "_" + ISO-3166-1 --> ํ๊ตญ : <fmt:setLocale value="ko_kr"/> ๊ธ์ก(์(ๅ)) : <fmt:formatNumber value="100000" type="currency" /><br> ๋ฏธ๊ตญ : <fmt:setLocale value="en_us"/> ๊ธ์ก (๋ฌ๋ฌ): <fmt:formatNumber value="100000" type="currency" /><br> ํ๋์ค : <fmt:setLocale value="fr_fr"/> ๊ธ์ก (์ ๋ก) : <fmt:formatNumber value="100000" type="currency" /><br> ์๊ตญ : <fmt:setLocale value="en_gb"/> ๊ธ์ก(ํ์ด๋) : <fmt:formatNumber value="100000" type="currency" /><br> ์ค๊ตญ : <fmt:setLocale value="zh_cn"/> ๊ธ์ก(์์,ๅ ) : <fmt:formatNumber value="100000" type="currency" /><br> ์ผ๋ณธ : <fmt:setLocale value="ja_jp"/> ๊ธ์ก (์,ๅ(ๅ)): <fmt:formatNumber value="100000" type="currency" /><br> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL : function
- ${fn:} : ๊ฐ์ข
ํจ์๋ค
- JSTL (function)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>ํจ์ ์ฌ์ฉ</title> </head> <body> <c:set var="str1" value="Functions <ํ๊ทธ>๋ฅผ ์ฌ์ฉํฉ๋๋ค. " /> <c:set var="str2" value="์ฌ์ฉ" /> <c:set var="tokens" value="1,2,3,4,5,6,7,8,9,10" /> length(str1) = ${fn:length(str1)} <br> toUpperCase(str1) = "${fn:toUpperCase(str1)}" <br> toLowerCase(str1) = "${fn:toLowerCase(str1)}" <br> substring(str1, 3, 6) = "${fn:substring(str1, 3, 6)}" <br> substringAfter(str1, str2) = "${fn:substringAfter(str1, str2)}" <br> substringBefore(str1, str2) = "${fn:substringBefore(str1, str2)}" <br> trim(str1) = "${fn:trim(str1)}" <br> replace(str1, src, dest) = "${fn:replace(str1, " ", "-")}" <br> indexOf(str1, str2) = "${fn:indexOf(str1, str2)}" <br> startsWith(str1, str2) = "${fn:startsWith(str1, 'Fun')}" <br> endsWith(str1, str2) = "${fn:endsWith(str1, "ํฉ๋๋ค.")}" <br> contains(str1, str2) = "${fn:contains(str1, str2)}" <br> containsIgnoreCase(str1, str2) = "${fn:containsIgnoreCase(str1, str2)}" <br> <c:set var="array" value="${fn:split(tokens, ',')}" /> join(array, "-") = "${fn:join(array, "-")}" <br> escapeXml(str1) = "${fn:escapeXml(str1)}" <br> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL EL : EL operation (์ฐ์ฐ์)
- JSTL (EL)
<%@ page language="java" contentType="text/html; charset=UTF-8"%> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>EL ์ฐ์ฐ์ ์ฌ์ฉ ์์ </title> </head> <body> <h3>\${5+7} = ${5+7}</h3> <h3>\${8-3} = ${8-3}</h3> <h3>\${6*3} = ${6*3}</h3> <h3>\${9/3} = ${9/3}</h3> <h3>\${10%3} = ${10%3}</h3> <h3>\${10==9} = ${10==9}</h3> <h3>\${5!=7} = ${5!=7}</h3> <h3>\${7<8} = ${7<8}</h3> <h3>\${8>8} = ${8>8}</h3> <h3>\${15<=9} = ${15<=9}</h3> <h3>\${7>=2} = ${7>=2}</h3> <h3>\${5+3==8 ? 8 : 10} = ${5+3==8 ? 8 : 10}</h3> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด
โ JSTL : custom Tag Lib (์ฌ์ฉ์ ์ ์ ํ๊ทธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ)
- JSTL (custom Tag Lib)
<%@ page contentType="text/html; charset=UTF-8" %> <%@ page session="false" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <%@ taglib prefix="elfunc" uri="/WEB-INF/tlds/el-functions.tld" %> <% java.util.Date today = new java.util.Date(); request.setAttribute("today", today); java.time.LocalDate today2 = java.time.LocalDate.now(); request.setAttribute("today2", today2); %> <!doctype html> <html lang="ko"> <head> <meta charset="UTF-8" /> <title>EL ํจ์ ํธ์ถ</title> </head> <body> ์ค๋์ ${elfunc:dateFormat(today)} ์ ๋๋ค. <hr> ์ค๋์ <fmt:formatDate value="${today}" pattern="yyyy๋ M์ d์ผ" />์ ๋๋ค. <hr> ์ค๋์ ${today2} ์ ๋๋ค. <hr> <fmt:parseDate var="tmp" value="${today2}" pattern="yyyy-M-d"/> ์ค๋์ <fmt:formatDate value="${tmp}" pattern="yyyy๋ M์ d์ผ" />์ ๋๋ค. <hr> <!-- ์๋์ ๊ฒฝ์ฐ๋ ์๋ฌ ์ ๋ฐ๋จ --> <%-- ์ค๋์ <fmt:formatDate value="${today2}" pattern="yyyy๋ M์ d์ผ" />์ ๋๋ค. --%> </body> </html>
โถ ์ถ๋ ฅํ๋ฉด