728x90
목차
- JSTL(JSP Standard Tag Liberary)
- JSTL 설정
- JSTL 사용
- a. core_forEach/if
- b. fmt
1. JSTL(JSP Standard Tag Liberary)
* 연산이나 if, for 등을 jsp에서 간편하게 사용할 수 있도록 만든 라이브러리
* 가독성이 높아진다.
2.JSTL 설정
* apache-tomcat-8.5.59 > webapps > examples > WEB-INF > lib 에 있는
taglibs-standard-impl-1.2.5.jar 과 taglibs-standard-spec-1.2.5.jar을 복사 해 apache-tomcat-8.5.59 > lib에 붙히기
3. JSTL 사용
* <%@ %>를 만들고 ctrl+space를 사용해 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 완성한다.
a. core : if, forEach 등과 같은 제어문을 사용가능 하게 하는 라이브러리
<c : forEach var="i" begin="1" end="5" step="1">
// var : 한바퀴 반복할 때 마다 변화되는 begin 값을 갱신
// begin : 시작값
// end : 끝 값
// step : 증가 값
</c : forEach>
<c : forEach var="v" items="${ array }" varStatus="cnt">
<li> cnt:${ cnt.index } / count:${ cnt.count } / ${v} </li>
// ${ cnt.index } : idex를 0번부터 html에 출력
// ${ cnt.count} : 순번을 1번부터 카운팅해 html에 출력
</c : forEach>
a-1. forEach
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
List<String> arrayTest = new ArrayList<>();
arrayTest.add("arr1");
arrayTest.add("arr2");
arrayTest.add("arr3");
request.setAttribute("arr", arrayTest);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<ul>
<c:forEach var="v" items="${ arr }" varStatus="cnt">
<li> idx : ${cnt.index} / ${v}</li>
</c:forEach>
</ul>
</body>
</html>
<c : if test=" ${ condition }">
</c:if>
a-2. for
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<ul>
<c:forEach var="i" begin="1" end="5">
<c:if test="${i mod 2 eq 0}">
<li><font color=red>짝수 : ${i} </font></li>
</c:if>
<c:if test="${i mod 2 eq 1}">
<li><font color=blue>홀수 : ${i} </font></li>
</c:if>
</c:forEach>
</ul>
</body>
</html>
b. fmt(format) : 날짜나 숫자형식의 포맷을 변경하는 라이브러리
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/fmt" %> <% |
728x90
'# WEB > Java&JSP' 카테고리의 다른 글
[JSP] 동영상재생페이지 만들기 (0) | 2020.12.16 |
---|---|
[JSP] EL표현식_JSP가독성 높히기 (0) | 2020.11.26 |
[JSP] Update_WEB에서 DB자원 수정하기 (0) | 2020.11.25 |
[JSP] Delete_WEB에서 DB자원 삭제하기 (0) | 2020.11.23 |
[JSP] Create_WEB에서 DB자원 삽입하기 (0) | 2020.11.21 |