1. JSTL (JSP Standard Tag Library)
<c:out value="${'Welcome to javaTpoint'}"/>
-> Welcome to javaTpoint을 출력
<c:import var="data" url="http://www.javatpoint.com"/>
-> data에 url정보를 넣어주는?
- c:set
- similar to jsp:setProperty action tag
- 표현된 결과를 설정하는데 사용
<c:set var="Income" scope="session" value="${4000*4}"/>
-> 4000*4의 결과값을 Income에다가 넣어서
-> Income을 c:out하면 web에 출력
<c:remove var="income"/>
-> income에 있는 내용을 삭제
<c:out value="${income}"/>해보면
아무값도 들어있지 않아서 아무글자도 뜨지 않음
- c:catch
- c:if
- set
- c:choose
- c:when
- c:otherwise
<c:choose>
<c:when test="${income <= 1000}"> </c:when>
<c:when test="${income > 10000}"></c:when>
<c:otherwise></c:otherwise>
</c:choose>
<c:forEach var="j" begin="1" end="3">
Item <c:out value="${j}"/><p>
</c:forEach>
- c:forTokens
- item을 delims만큼 끊어서 var에 저장
<c:forTokens items="Rahul-Nakul-Rajesh" delims="-" var="name"> </c:forTokens>
- c:param
- import태그의 url에 매개변수를 추가한다.
- c:redirect
- c:url
- fn:contains()
- It is used to test if an input string containing the specified substring in a program.
- fn:contains(string, sbustring)
- string이 substring을 포함하면 return true, 그렇지 않으면 return false
- 대소문자 구분
- fn:contains(String, 'javatpoint')
- String에 javatpoint가 포함되어 있는지 test
- fn:containsIgnoreCase()
- It is used to test if an input string contains the specified substring as a case insensitive way.
- fn:containsIgnoreCase(string, sbustring)
- 대소문자 구분없이 string이 substring을 포함하면 return true, 그렇지 않으면 return false
- fn:containsIgnoreCase(String, 'javatpoint')
- fn:endsWith()
- It is used to test if an input string ends with the specified suffix.
- fn:endsWith(string, suffix)
- string이 suffix로 끝나면 return true, 그렇지 않으면 return false
- fn:escapeXml()
- It escapes the characters that would be interpreted as XML markup.
- fn:escapeXml(string)
- stting에 XML과 HTML에서 < >& ' " 문자들이 있으면, XML ENTITY CODE로 바꿔준뒤 문자열 반환
- fn:indexOf()
- It returns an index within a string of first occurrence of a specified substring.
- fn:indexOf(string, sbustring)
- string에서 substring이 처음으로 나타나는 index 반환
- 띄어쓰기 포함
- fn:trim()
- It removes the blank spaces from both the ends of a string.
- fn:trim(string)
- string 앞뒤의 공백을 모두 제거한 후 반환
- fn:startsWith()
- It is used for checking whether the given string is started with a particular string value.
- fn:startsWith(string, prefix)
- string이 prefix로 시작하면 return true, 그렇지 않으면 return false
- fn:split()
- It splits the string into an array of substrings.
- fn:split(string, separator)
- string내의 문자열 separetor에 따라 나누어서 배열로 구성해서 반환
- fn:join(array, separator)
- array요소들을 separator를 구분자로 하여 연결해서 반환
- fn:toLowerCase()
- It converts all the characters of a string to lower case.
- fn:toLowerCase(string)
- fn:toUpperCase()
- It converts all the characters of a string to upper case.
- fn:toUpperCase(string)
- fn:substring()
- It returns the subset of a string according to the given start and end position.
- fn:substring(string, begin, end)
- string에서 begin index에서 시작해서 end index에 끝나는 부분의 문자열 반환
- fn:substringAfter()
- It returns the subset of string after a specific substring.
- fn:substringAfter(string, sbustring)
- string에서 substring의 다음 문자열 반환
- fn:substringBefore()
- It returns the subset of string before a specific substring.
- fn:substringBefore(string, sbustring)
- string에서 substring의 이전 문자열 반환
- fn:length()
- It returns the number of characters inside a string, or the number of items in a collection.
- fn:length(string)
- 배열, 컬렉션의 요소 개수, 문자열의 문자 개수를 반환 (int)
- fn:replace()
- It replaces all the occurrence of a string with another string sequence.
- fn:replace(string, before, after)
- string에 있는 before 문자열을 after 문자열로 모두 변경해서 반환
- <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
- fmt:parseNumber
- It is used to Parses the string representation of a currency, percentage or number.
- fmt:timeZone
- It specifies a parsing action nested in its body or the time zone for any time formatting.
- fmt:formatNumber
- It is used to format the numerical value with specific format or precision.
- fmt:parseDate
- It parses the string representation of a time and date.
- fmt:bundle
- It is used for creating the ResourceBundle objects which will be used by their tag body.
- fmt:setTimeZone
- It stores the time zone inside a time zone configuration variable.
- fmt:setBundle
- It loads the resource bundle and stores it in a bundle configuration variable or the named scoped variable.
- fmt:message
- It display an internationalized message.
- fmt:formatDate
- It formats the time and/or date using the supplied pattern and styles.
- <%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
- x:out
- Similar to <%= ... > tag, but for XPath expressions.
- <x:out select="$output/vegetables/vegetable[1]/name" />
- x:parse
- It is used for parse the XML data specified either in the tag body or an attribute.
- <x:parse xml="${file}" var="output"/>
- x:set
- It is used to sets a variable to the value of an XPath expression.
- <x:set var="file" select="$output/vegetables/vegetable[3]/price"/>
- set
- x:choose
- It is a conditional tag that establish a context for mutually exclusive conditional operations.
- x:when
- It is a subtag of that will include its body if the condition evaluated be 'true'.
- x:otherwise
- It is subtag of that follows tags and runs only if all the prior conditions evaluated be 'false'.
- <x:when> and <x:otherwise>는 if-else statement와 같이 작동한다. <x:choose>안에 무조건 위치해야한다.
<x:choose>
<x:when select="$output//book/author = 'Chetan bhagat'"> </x:when>
<x:when select="$output//book/author = 'Brad Bird'"> </x:when>
<x:otherwise> </x:otherwise>
</x:choose>
- x:if
- It is used for evaluating the test XPath expression and if it is true, it will processes its body content.
- 조건이 true인 경우 <x:if> </x:if>안에 있는 내용 실행
- x:transform
- It is used in a XML document for providing the XSL(Extensible Stylesheet Language) transformation.
- xsl파일과 xml파일을 결합해 새로운 문서를 생성
- x:param
- It is used along with the transform tag for setting the parameter in the XSLT style sheet.
- xslt 스타일 시트에서 매개변수를 설정하는데 사용
- <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
- sql:setDataSource
- It is used for creating a simple data source suitable only for prototyping.
- DB에 접속하기 위한 데이터 소스 생성
- sql:query
- It is used for executing the SQL query defined in its sql attribute or the body.
- sql:update
- It is used for executing the SQL update defined in its sql attribute or in the tag body.
- sql:param
- It is used for sets the parameter in an SQL statement to the specified value.
- sql:dateParam
- It is used for sets the parameter in an SQL statement to a specified java.util.Date value.
- sql:transaction
- It is used to provide the nested database action with a common connection.
참고: https://www.javatpoint.com/jstl