๋ฐ์ํ
thymeleaf์ fragment ๊ฐ์ ๊ธฐ๋ฅ์ jstl์์ ์ฌ์ฉํ๊ณ ์ถ์ ๋
jstl ์ ๋ด์ฅ๊ฐ์ฒด ์ปค์คํ ๊ธฐ๋ฅ์ ํ์ฉํด ๊ตฌํํ ์ ์๋ค.
thymeleaf fragment์ ๊ฐ์ด ๋ฐ๋ณต๋๋ ๊ตฌ๋ฌธ ์์ฑ์ ์ ์ฉํ๊ฒ ์ฌ์ฉํ ์ ์์
pom.xml ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ถ๊ฐ
... ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ถ๊ฐ ์ฝ๋
<!-- jsp -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>provided</scope>
</dependency>
<!-- jstl -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
...
jsp ํ์ผ ์์ฑ
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="mytag" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
...
</head>
<body>
...
<mytag:${๋ถ๋ฌ์ฌ .tag ํ์ผ๋ช
์์ฑ} />
...
</body>
</html>
์๋จ์ <%@ taglib ... > ๋ฅผ ์ด์ฉํด ๋ถ๋ฌ์ฌ tag directory ๊ฒฝ๋ก๋ฅผ ์ธํ ํด์ค๋ค.
(tag directory ์๋ .tag ํ์ผ๋ค์ด ๋ค์ด๊ฐ์๋๋ก ์ธํ ํ๋ค)
<%@ taglib ... > ์์ฑ ๊ตฌ๋ฌธ ๊ฐ์ ๊ฒฝ์ฐ์๋
ํ๋ก์ ํธ์ ์ธํ ๋ jsp ๋ฒ์ ์๋ฐ๋ผ ๋ค๋ฅด๋ค.
<%-- JSP 1.2 --%>
<%@ taglib uri="/WEB-INF/myTag.tld" prefix="mytag" %>
<%-- JSP 2.0 --%>
<%@ taglib tagdir="/WEB-INF/tags" prefix="myTag" %>
1.2 ๋ฒ์ ์ธํ ์ ๊ฒฝ์ฐ WEB-INF ํด๋ ์์ .tld์ ์์ฑํด ์ปค์คํ tag ์ธํ ์ ํด์ค์ผ ํ๋ค.
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<tlib-version>1.0</tlib-version>
<short-name>example</short-name>
<uri>http://example.com/tags</uri> <!-- tag directory ๊ฒฝ๋ก -->
<tag>
<name>hello</name> <!-- tag ๋ถ๋ฌ์ฌ ๋ ์ฌ์ฉํ ์ด๋ฆ -->
<tag-class />
<body-content>empty</body-content> <!-- ํ๊ทธ์ ๋ฐ๋ ๋ด์ฉ ์ ์ : empty,tagdependent,scriptless -->
</tag>
</taglib>
๋ฐ์ํ
'๊ฐ๋ฐ ์ด์ผ๊ธฐ > JAVA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Java - ์ต๋๊ฐ ์ต์๊ฐ ๊ฐ์ ธ์ค๊ธฐ Math.max() / Math.min() (0) | 2024.01.16 |
---|---|
Java - repeat ๋ฉ์๋ ์ด์ฉํด ๋ณ์ฐ๊ธฐ (2) | 2023.12.20 |
Java - ์ ๋ ฅ๋ฐ์ ์๋ฅผ ๋ชจ๋ ๋ํ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅํ๋ ์์ (2) | 2023.12.10 |
Java - ์์ธ ๋ฐ์ ์ฝ๋ (throw new IllegalArgumentException) (0) | 2023.07.04 |
Java - ์ดํด๋ฆฝ์ค ํ๊ฒฝ ์ค์ (0) | 2023.07.01 |