• Home
  • About
    • ming photo

      ming

      studying

    • Learn More
    • Twitter
    • Facebook
    • Instagram
    • Github
    • Steam
  • Archive
    • All Posts
    • All Tags
    • All categories
  • categories
    • HTML+CSS+JavaScript
    • JAVA
    • Algorithm
    • DB
    • JSP
    • ์ •๋ณด์ฒ˜๋ฆฌ๊ธฐ์‚ฌ
    • Spring
    • Thymeleaf
    • ๊ธฐ์ˆ ๋ฉด์ ‘
  • Projects

JSP - JSP 2.3 & Servlet3.1 - JSTL๊ณผEL : core,format,function,el,custom tag EL

26 Mar 2021

๐Ÿ”ท 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>&lt;c:out&gt;</title>
      </head>
      <body>
    
      <!-- xml ํƒœ๊ทธ ๋ฐ & ํŠน์ˆ˜๋ฌธ ์ž ํ‘œ๊ธฐ์—์„œ์˜ ์ฐจ์ด -->
      <c:set var="temp" value="JSTL &amp; EL, <tag> " />
      <!-- ๋งŒ์•ฝ 2), 3)์˜ ๊ฒฝ์šฐ์—์„œ ํƒœ๊ทธ๊ฐ€ ์ œ๋Œ€๋กœ ๋‚˜์˜ค๋ ค๋ฉด ์•„๋ž˜์˜ ๊ตฌ๋ฌธ์œผ๋กœ ๊ต์ฒดํ•ฉ๋‹ˆ๋‹ค. -->
      <!--<c:set var="temp" value="JSTL &amp; EL, &lt;tag&gt; " /> -->
    
      <!-- 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>
    

โ–ถ ์ถœ๋ ฅํ™”๋ฉด c,out

โœ” 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>
    

โ–ถ ์ถœ๋ ฅํ™”๋ฉด c,url

โœ” 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>
    

โ–ถ ์ถœ๋ ฅํ™”๋ฉด c,if

โœ” 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>
    

โ–ถ ์ถœ๋ ฅํ™”๋ฉด c,choose

โœ” 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>
    

โ–ถ ์ถœ๋ ฅํ™”๋ฉด c,catch

โœ” 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>
    

โ–ถ ์ถœ๋ ฅํ™”๋ฉด c,foreach

โœ” 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>
    

โ–ถ ์ถœ๋ ฅํ™”๋ฉด forTokens

โœ” 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>ํŽ˜์ด์ง€ ์‚ฝ์ž… : &lt;c:import&gt;</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>
    

    โ–ถ ์ถœ๋ ฅํ™”๋ฉด c,import

โœ” 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>
    

    โ–ถ ์ถœ๋ ฅํ™”๋ฉด redirect

โœ” 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>
    

    โ–ถ ์ถœ๋ ฅํ™”๋ฉด dateformat

โœ” 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>
    

    โ–ถ ์ถœ๋ ฅํ™”๋ฉด c,setlocal

โœ” 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>
    

    โ–ถ ์ถœ๋ ฅํ™”๋ฉด timezone

โœ” 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>
    

    โ–ถ ์ถœ๋ ฅํ™”๋ฉด bundle

โœ” 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>
    

    โ–ถ ์ถœ๋ ฅํ™”๋ฉด c,number

โœ” 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>
    

    โ–ถ ์ถœ๋ ฅํ™”๋ฉด usefun

โœ” 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>
    

    โ–ถ ์ถœ๋ ฅํ™”๋ฉด eloperation

โœ” 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>
    

โ–ถ ์ถœ๋ ฅํ™”๋ฉด custon



Share Tweet +1