티스토리 뷰

☠️ Java

JSTL(Java Standard Tag Library)-Core

James Wetzel 2024. 8. 27. 09:35
728x90
반응형
기능 태그 설명
변수 지원 <c:set>  
<c:remove>  
흐름 제어 <c:if>  
<c:choose>  
<c:forEach>  
<c:forTokens>  
URL 처리 <c:import>  
<c:redirect>  
<c:url>  
기타 태그 <c:catch>  
<c:out>  

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    isELIgnored="false"
    import="java.util.*"
 %>
 
 <%
	List<String> dataList = new ArrayList<String>();
	dataList.add("hello");
	dataList.add("world");
	dataList.add("정훈입니다.");
%>
    
<!-- JSTL: core  -->   
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 
<c:set var="id" value="jh.jang" scope="page" />
<c:set var="name" value="장정훈" scope="page" />
<c:set var="contextPath" value="${pageContext.request.contextPath}" />
<c:set var="list" value="<%= dataList %>" />

<c:remove var="contextPath" />

<c:url var="url" value="/rootPath/path.jsp">
	<c:param name="id" value="jh.jang" />
	<c:param name="name" value="장정훈" />
</c:url>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

	<h1>값 출력</h1>
	<p>id = ${ id }</p>
	<p>contextPath = ${ contextPath }</p>
	<p>id = <c:out value="${ id }" /></p>
	<p>특수 문자 = <c:out value="&lt;" escapeXml="true" /></p>
	<p>특수 문자 = <c:out value="&lt;" escapeXml="false" /></p>
	<br>
	
	
	<h1>c:if Ex</h1>
	<c:if test="${ id == 'jh.jang' }">
		<p>id = jh.jang</p>
	</c:if>
	<br>
	
	
	<h1>c:chose Ex</h1>
	<c:choose>
		<c:when test="${ empty contextPath }"> 
			<p> "contextPath" value deleted by "c:remove" </p> 
		</c:when>
		
		<c:otherwise>
			<p> ${ contextPath } </p>
		</c:otherwise> 
	</c:choose>
	<br>
	
	<h1>c:forEach Ex1</h1>
	<c:forEach var="i" begin="1" end="10" step="1" varStatus="loop">
		<p>i = ${ i }</p>
		<p>count = ${ loop.count }</p>
		<p>index = ${ loop.index }</p>
		<p>first = ${ loop.first }</p>
		<p>last = ${ loop.last }</p>
	</c:forEach>
	<br>
	
	<h1>c:forEach Ex2</h1>
	<c:forEach var="i" begin="1" end="10" step="2">
		<p>${ i }</p>
	</c:forEach>
	<br>
	
	<h1>c:forEach Ex3</h1>
	<c:forEach var="data" items="${ list }">
		<p>${ data }</p>
	</c:forEach>
	<br>
	
	<h1>c:forTokens Ex</h1
	<c:set var="fruits" value="사과,배,복숭아" />
	<c:forTokens var="token" items="${ fruits }" delims=",">
		<p>${ token }</p>
	</c:forTokens>
	<br>
	
	<h1>c:url Ex</h1>
	<a href="${ url }">url Ex test</a>
	
	<h1>c:redirect Ex</h1>
	<%-- 
	
	<c:redirect url="rootPath/test.jsp">
		<c:param name="id" value="jh.jang" />
		<c:param name="name" value="장정훈" />
	</c:redirect> 
	
	--%> 
</body>
</html>

 

 

 

scope 유형

page, request, session, application

 

 

비고]

error: javax/servlet/jsp/tagext/TagLibraryValidator

 

error: javax/servlet/jsp/tagext/TagLibraryValidator

에러 메세지java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/TagLibraryValidator 원인Tomcat(톰캣)에서 런타임시 "javax/servlet/jsp/tagext/TagLibraryValidator" 클래스를 찾지 못해서 그런것 같다. 체크 사항Java Versionj

jangjeonghun.tistory.com

 

728x90
반응형