JSP Custom Tags - YooYoungmo/AEP GitHub Wiki

์ฐธ๊ณ  ์ž๋ฃŒ

JSP Custom Tag Spike ๊ณผ์ • ์š”์•ฝ

ใ„ฑ. java-appliction project๋ฅผ web-project๋กœ ๋ณ€๊ฒฝ.

  • Project Structure -> Facets : web ์ถ”๊ฐ€

ใ„ด. maven์„ ํ†ตํ•œ javax ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€.

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.1</version>
            <scope>provided</scope>
        </dependency>

ใ„ท. ์ปค์Šคํ…€ ํƒœ๊ทธ ์ •์˜.

  1. .tld ํŒŒ์ผ ์ •์˜.
  2. SimpleTagSupport ์ƒ์† Class ์ •์˜.
  3. web.xml์— ๋“ฑ๋ก.
    <jsp-config>
        <taglib>
            <taglib-uri>http://journaldev.com/jsp/tlds/mytags</taglib-uri>
            <taglib-location>/WEB-INF/custom.tld</taglib-location>
        </taglib>
    </jsp-config>

ใ„น. jsp ํŽ˜์ด์ง€ ์ƒ์„ฑ.

  • ํƒœ๊ทธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ ์„ ์–ธ ๋ฐ ํƒœ๊ทธ ์‚ฌ์šฉ.
<%@ taglib uri="http://journaldev.com/jsp/tlds/mytags" prefix="mytags"%>
<html>
<head></head>
<body>
    <mytags:HelloWorld />
</body>
</html>

ใ…. custom tag ๋™์ž‘ ํ™•์ธ.

  1. maven์„ ํ†ตํ•œ tomcat ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ถ”๊ฐ€.
  2. maven ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•œ tomcat ์„œ๋ฒ„ ๊ธฐ๋™.
  3. ํŽ˜์ด์ง€ ์ ‘์† ํ•˜์—ฌ ๊ฒฐ๊ณผ ํ™•์ธ.
โš ๏ธ **GitHub.com Fallback** โš ๏ธ