Spring
JSP : Standard JSP Tag Library (JSTL) - Functional Tags
dodop
2021. 6. 18. 19:02
function태그는 다음의 코드를 가지고 있어야 한다.
function-test.jsp
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<body>
<c:set var="data" value="luv2code"/>
Length of the string <b>${data}</b> : ${fn:length(data)}
</body>
</html>
uppercase, startswith를 추가하자.
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<body>
<c:set var="data" value="luv2code"/>
Length of the string <b>${data}</b> : ${fn:length(data)}
<br/>
Uppercase version of the string <b>${data }</b> : ${fn:toUpperCase(data) }
<br/>
Does the string <b>${data }</b> start with <b>luv</b>? : ${fn:startsWith(data, "luv") }
</body>
</html>
이제 split, join을 해보자.
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<body>
<c:set var="data" value="Seoul, Busan, Daegu, Junju"/>
<h3>Split Demo</h3>
<c:set var="citiesArray" value = "${fn:split(data, ',') }"/>
<c:forEach var="tempCity" items="${citiesArray }">
${tempCity} <br/>
</c:forEach>
<h3>Join Demo</h3>
<c:set var="fun" value="${fn:join(citiesArray, '*') }"/>
Result of joining: ${fun }
</body>
</html>