웹이야기

JSTL 과 EL 본문

전자정부표준프레임워크

JSTL 과 EL

yeon.Biju 2020. 8. 28. 13:19

JSTL  : JavaServer Pages Standard Tag Library

EL : Expression Language (표현언어)

 

JSTL은 JSP단에 EL과 함께 쓰여 JSP를 덜 복잡하게(자바코드형태가 많이 쓰이는 것보다) 만들어준다.

 

JSTL에는 5개 영역(우리가 대부분 쓰는 JSTL은 버전이 1.1일 것이다.)이 있다.

 

JSTL core

JSTL fmt

JSTL sql

JSTL XML

JSTL functios

 

 

1, JSTL core

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

위와 같이 상단에 선언이 되어 있어야 하며, prefix 는 임의로 지정이 가능하지만 대부분의 경우 그냥 사용하는 것 같다.

 

1) catch

   - Catches any Throwable that occurs in its body and optionally exposes it.


2) choose

   - Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by <when> and <otherwise>


3) if

   - Simple conditional tag, which evalutes its body if the supplied condition is true and optionally exposes a Boolean scripting variable representing the evaluation of this condition


4) import

   - Retrieves an absolute or relative URL and exposes its contents to either the page, a String in 'var', or a Reader in 'varReader'.


5) forEach

   - The basic iteration tag, accepting many different collection types and supporting subsetting and other functionality


6) forTokens

   - Iterates over tokens, separated by the supplied delimeters


7) out

   - Like <%= ... >, but for expressions.


8) otherwise

   - Subtag of <choose> that follows <when> tags and runs only if all of the prior conditions evaluated to 'false'


9) param

   - Adds a parameter to a containing 'import' tag's URL.


10) redirect

   - Redirects to a new URL.


11) remove

   - Removes a scoped variable (from a particular scope, if specified).


12) set

   - Sets the result of an expression evaluation in a 'scope'


13) url

   - Creates a URL with optional query parameters.


14) when

   - Subtag of <choose> that includes its body if its condition evalutes to 'true'

 

 

2. JSTL fmt

- fmt 가 format(또는 formatting)의 약자이지 않을까 추측해본다. 

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

위와 같이 상단에 선언이 되어 있어야 하며, prefix 는 임의로 지정이 가능하지만 대부분의 경우 그냥 사용하는 것 같다.

 

1) requestEncoding

   - Sets the request character encoding


2) setLocale

   - Stores the given locale in the locale configuration variable


3) timeZone

   - Specifies the time zone for any time formatting or parsing actions nested in its body


4) setTimeZone

   - Stores the given time zone in the time zone configuration variable


5) bundle

   - Loads a resource bundle to be used by its tag body


6) setBundle

   - Loads a resource bundle and stores it in the named scoped variable or the bundle configuration variable


7) message

   - Maps key to localized message and performs parametric replacement


8) param

   - Supplies an argument for parametric replacement to a containing <message> tag


9) formatNumber

   - Formats a numeric value as a number, currency, or percentage


10) parseNumber

   - Parses the string representation of a number, currency, or percentage


11) formatDate

   - Formats a date and/or time using the supplied styles and pattern


12) parseDate

   - Parses the string representation of a date and/or time

 

3. JSTL sql

   - sql 관련된 JSTL.

   - 한번도 사용해본 적은 없다. 

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

위와 같이 상단에 선언이 되어 있어야 하며, prefix 는 임의로 지정이 가능하지만 대부분의 경우 그냥 사용하는 것 같다.

 

1) transaction

   - Provides nested database action elements with a shared Connection, set up to execute all statements as one transaction.


2) query

   - Executes the SQL query defined in its body or through the sql attribute.


3) update

   - Executes the SQL update defined in its body or through the sql attribute.


4) param

   - Sets a parameter in an SQL statement to the specified value.


5) dateParam

   - Sets a parameter in an SQL statement to the specified java.util.Date value.

 

6) setDataSource

   - Creates a simple DataSource suitable only for prototyping.

 

4. JSTL XML

   - XML과 관련된 JSTL.

   - 한번도 사용해본 적은 없다. 

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

위와 같이 상단에 선언이 되어 있어야 하며, prefix 는 임의로 지정이 가능하지만 대부분의 경우 그냥 사용하는 것 같다.

 

1) choose

   - Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by <when> and <otherwise>


2) out

   - Like <%= ... >, but for XPath expressions.


3) if

   - XML conditional tag, which evalutes its body if the supplied XPath expression evalutes to 'true' as a boolean


4) forEach

   - XML iteration tag.


5) otherwise

   - Subtag of <choose> that follows <when> tags and runs only if all of the prior conditions evaluated to 'false'


6) param

   - Adds a parameter to a containing 'transform' tag's Transformer


7) parse

   - Parses XML content from 'source' attribute or 'body'


8) set

   - Saves the result of an XPath expression evaluation in a 'scope'


9) transform

   - Conducts a transformation given a source XML document and an XSLT stylesheet


10) when

   - Subtag of <choose> that includes its body if its expression evalutes to 'true'

 

5. JSTL functios

   - 함수(function)모음.

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

위와 같이 상단에 선언이 되어 있어야 하며, prefix 는 임의로 지정이 가능하지만 대부분의 경우 그냥 사용하는 것 같다.

 

1) contains( java.lang.String, java.lang.String)

   - Tests if an input string contains the specified substring.

 

2) containsIgnoreCase( java.lang.String, java.lang.String)

   - Tests if an input string contains the specified substring in a case insensitive way.

 

3) endsWith( java.lang.String, java.lang.String)

   - Tests if an input string ends with the specified suffix.

 

4) escapeXml( java.lang.String)

   - Escapes characters that could be interpreted as XML markup.

 

5) indexOf( java.lang.String, java.lang.String)

   - Returns the index withing a string of the first occurrence of a specified substring.

 

6) join( java.lang.String[], java.lang.String)

   - Joins all elements of an array into a string.

 

7) length( java.lang.Object)

   - Returns the number of items in a collection, or the number of characters in a string.

 

8) replace( java.lang.String, java.lang.String, java.lang.String)

   - Returns a string resulting from replacing in an input string all occurrences of a "before" string into an "after" substring.

 

9) split( java.lang.String, java.lang.String)

   - Splits a string into an array of substrings.

 

10) startsWith( java.lang.String, java.lang.String)

   - Tests if an input string starts with the specified prefix.

 

11) substring( java.lang.String, int, int)

   - Returns a subset of a string.

 

12) substringAfter( java.lang.String, java.lang.String)

   - Returns a subset of a string following a specific substring.

 

13) substringBefore( java.lang.String, java.lang.String)

   - Returns a subset of a string before a specific substring.

 

14) toLowerCase( java.lang.String)

   - Converts all of the characters of a string to lower case.

 

15) toUpperCase( java.lang.String)

   - Converts all of the characters of a string to upper case.

 

16) trim( java.lang.String)

   - Removes white spaces from both ends of a string.

Comments