1. 이클립스 들어간다.
2. 동적 웹 페이지 생성(Dynamic Web Project)
3. www.luv2code.com/download-jstl 에서 압축 파일을 다운
4. 압축을 풀고 거기에 있는 두개의 jar 파일을 WebContent/Web-INF/lib 폴더에 넣어준다. 끝!
5. 예제를 풀어보자
<%@ page contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:set var = "stuff" value = "<%=new java.util.Date() %>"/>
Time on the server is ${stuff }
</body>
</html>
JSTL라이브러리를 사용하는 방법
화면 상단에
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core %>
입력할 때에 t 누르고 ctrl+space 누르면 자동으로 세팅 된다.
body에 가서
<c:set var = "stuff" value = "<%=함수%>"/>
호출해서 사용 할 때에
EL표현식 사용 가능
${stuff}
Time on the server is Fri Aug 06 23:32:56 KST 2021
요런 식이 출력이 된다.
원래였다면
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@ page contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:set var = "stuff" value = "<%=new java.util.Date() %>"/>
<%Date time = new Date();%>
Time on the server is ${stuff }<br/>
Time on the server is <%out.println(time); %>
</body>
</html>
이런 식으로 복잡하게 출력해야할 것을
훨씬 간단하게 표현할 수 있게 되었다. 사실 그냥 <%=new java.util.Date()%> 로 출력이 가능하지만 저렇게 표현하면 재사용, 유지보수 등 을 못하게 된다.
'Udemy' 카테고리의 다른 글
| JSTL Core Tag -<choose> (0) | 2021.08.07 |
|---|---|
| JSTL Core Tag - <if> (0) | 2021.08.07 |
| JSTL Core Tag (Looping with forEach) (0) | 2021.08.07 |
| JSTL Core Tag-<forEach> 반복문 (0) | 2021.08.07 |
| JSP: Cookie 사용하기 예제 (0) | 2021.08.06 |