[JSP] JSTL ( JSP Standard Tag Library )
JSTL λ μ μ©ν JSP νκ·Έλ€μ λͺ¨μλμ λΌμ΄λΈλ¬λ¦¬μ λλ€. 컀μ€ν νκ·Έλ₯Ό JSTL tagsμ ν΅ν©ν μ μλ νλ μμν¬λ μ 곡νλ―λ‘ μμλμλ©΄ μ’μκ±°μμ.
JSTLνκ·Έλ κΈ°λ₯λ³λ‘ λΆλ₯κ° λ©λλ€.
Core Tags
Formatting tags
SQL tags
XML tags
JSTL Functions
JSTL μ€μΉνκΈ°
Apache Tomcat container λ₯Ό μ¬μ©μ€μ΄λ©΄ μλ λκ°μ§ μ€ν μΌλ‘ μ€μΉκ° μλ£λ©λλ€.
Apache Standard Taglib μ΄κ³³μμ λΌμ΄λΈλ¬λ¦¬λ₯Ό λ€μ΄λ‘λνκ³ μμΆμ νμ΄μ£ΌμΈμ.
μμΆμ΄ νλ¦° λλ ν 리λ΄μ libλλ ν 리μ JAR νμΌλ€μ μ¬λ¬λΆμ΄ μ¬μ©νλ €λ μ ν리μΌμ΄μ μ webapps\ROOT\WEB-INF\lib λλ ν 리μμ λ£μ΄μ£ΌμΈμ. ( μ΄κ±°λ μ΄ν΄λ¦½μ€μμ μ§μ νμ€ μ μλ건 μμμ£ ? )
νκ·ΈλΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©νλ €λ©΄ <taglib> λλ ν°λΈλ₯Ό JSP νμ΄μ§ μ μΌ μμͺ½μ μ μΈν΄μ£Όμ μΌ ν©λλ€.
Core Tags:
JSTL νκ·Έ μ€μμ κ°μ₯ λ§μ΄ μ¬μ©λλ νκ·Έμ λλ€.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Tag | Description |
---|---|
<c:out > | Like <%= ... >, but for expressions. |
<c:set > | Sets the result of an expression evaluation in a 'scope' |
<c:remove > | Removes a scoped variable (from a particular scope, if specified). |
<c:catch> | Catches any Throwable that occurs in its body and optionally exposes it. |
<c:if> | Simple conditional tag which evalutes its body if the supplied condition is true. |
<c:choose> | Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by <when> and <otherwise> |
<c:when> | Subtag of <choose> that includes its body if its condition evalutes to 'true'. |
<c:otherwise > | Subtag of <choose> that follows <when> tags and runs only if all of the prior conditions evaluated to 'false'. |
<c:import> | Retrieves an absolute or relative URL and exposes its contents to either the page, a String in 'var', or a Reader in 'varReader'. |
<c:forEach > | The basic iteration tag, accepting many different collection types and supporting subsetting and other functionality . |
<c:forTokens> | Iterates over tokens, separated by the supplied delimeters. |
<c:param> | Adds a parameter to a containing 'import' tag's URL. |
<c:redirect > | Redirects to a new URL. |
<c:url> | Creates a URL with optional query parameters |
Formatting tags:
ν¬λ§€ν κ΄λ ¨ νκ·Έλ€μ λλ€.λ€κ΅μ Web μ¬μ΄νΈλ₯Ό λ§λ€λ μ μ©νλ€κ³ νλ€μ.
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
Tag | Description |
---|---|
<fmt:formatNumber> | To render numerical value with specific precision or format. |
<fmt:parseNumber> | Parses the string representation of a number, currency, or percentage. |
<fmt:formatDate> | Formats a date and/or time using the supplied styles and pattern |
<fmt:parseDate> | Parses the string representation of a date and/or time |
<fmt:bundle> | Loads a resource bundle to be used by its tag body. |
<fmt:setLocale> | Stores the given locale in the locale configuration variable. |
<fmt:setBundle> | Loads a resource bundle and stores it in the named scoped variable or the bundle configuration variable. |
<fmt:timeZone> | Specifies the time zone for any time formatting or parsing actions nested in its body. |
<fmt:setTimeZone> | Stores the given time zone in the time zone configuration variable |
<fmt:message> | To display an internationalized message. |
<fmt:requestEncoding> | Sets the request character encoding |
SQL tags:
JSTL SQL νκ·Έλ κ΄κ³ν λ°μ΄νλ² μ΄μ€ μμ€ν μ νΈλ€λ§ν μ μμ΅λλ€. ( Oracle, MySQL, Microsoft SQL Server )
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
Tag | Description |
---|---|
<sql:setDataSource> | Creates a simple DataSource suitable only for prototyping |
<sql:query> | Executes the SQL query defined in its body or through the sql attribute. |
<sql:update> | Executes the SQL update defined in its body or through the sql attribute. |
<sql:param> | Sets a parameter in an SQL statement to the specified value. |
<sql:dateParam> | Sets a parameter in an SQL statement to the specified java.util.Date value. |
<sql:transaction > | Provides nested database action elements with a shared Connection, set up to execute all statements as one transaction. |
XML tags:
JSTL XML νκ·Έλ JSPμμ XML λ¬Έμλ₯Ό μμ± λ° μ‘°μν μ μλλ‘ ν΄μ€λλ€. νμ§λ§ XMLμ νμ±νκ±°λ λ°μ΄νλ₯Ό λ³ννκ±°λ XPath ννμμ μ¬μ©νλ €λ©΄ μΆκ°μ μΈ μ»€μ€ν νκ·Έκ° νμν©λλ€.
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
μλμ λ jarνμΌλ <Tomcat Installation Directory>\lib μ μΆκ°ν΄μ£Όμ μΌ ν©λλ€.
XercesImpl.jar: Download it from http://www.apache.org/dist/xerces/j/
xalan.jar: Download it from http://xml.apache.org/xalan-j/index.html
Tag | Description |
---|---|
<x:out> | Like <%= ... >, but for XPath expressions. |
<x:parse> | Use to parse XML data specified either via an attribute or in the tag body. |
<x:set > | Sets a variable to the value of an XPath expression. |
<x:if > | Evaluates a test XPath expression and if it is true, it processes its body. If the test condition is false, the body is ignored. |
<x:forEach> | To loop over nodes in an XML document. |
<x:choose> | Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by <when> and <otherwise> |
<x:when > | Subtag of <choose> that includes its body if its expression evalutes to 'true' |
<x:otherwise > | Subtag of <choose> that follows <when> tags and runs only if all of the prior conditions evaluated to 'false' |
<x:transform > | Applies an XSL transformation on a XML document |
<x:param > | Use along with the transform tag to set a parameter in the XSLT stylesheet |
JSTL Functions:
JSTL μ νμ€ ν¨μλ€μ μ 곡νκ³ μμ΅λλ€. λλΆλΆ μ€νΈλ§κ΄λ ¨ ν¨μλ€μ΄μ£ .
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
Function | Description |
---|---|
fn:contains() | Tests if an input string contains the specified substring. |
fn:containsIgnoreCase() | Tests if an input string contains the specified substring in a case insensitive way. |
fn:endsWith() | Tests if an input string ends with the specified suffix. |
fn:escapeXml() | Escapes characters that could be interpreted as XML markup. |
fn:indexOf() | Returns the index withing a string of the first occurrence of a specified substring. |
fn:join() | Joins all elements of an array into a string. |
fn:length() | Returns the number of items in a collection, or the number of characters in a string. |
fn:replace() | Returns a string resulting from replacing in an input string all occurrences with a given string. |
fn:split() | Splits a string into an array of substrings. |
fn:startsWith() | Tests if an input string starts with the specified prefix. |
fn:substring() | Returns a subset of a string. |
fn:substringAfter() | Returns a subset of a string following a specific substring. |
fn:substringBefore() | Returns a subset of a string before a specific substring. |
fn:toLowerCase() | Converts all of the characters of a string to lower case. |
fn:toUpperCase() | Converts all of the characters of a string to upper case. |
fn:trim() | Removes white spaces from both ends of a string. |
Reference : http://www.tutorialspoint.com/jsp/jsp_standard_tag_library.htm