본문 바로가기

JSP

SimpleTagSupport 클래스를 이용해서 태그 클래스 작성


StartLineTag.java 


package customaction;

 

import java.io.IOException;

 

import javax.servlet.jsp.JspContext;

import javax.servlet.jsp.JspException;

import javax.servlet.jsp.JspWriter;

import javax.servlet.jsp.tagext.SimpleTagSupport;

 

public class StartLineTag extends SimpleTagSupport {

 

    @Override

    public void doTag() throws JspException, IOException {

         // TODO Auto-generated method stub

         JspContext context = getJspContext();

         JspWriter out = context.getOut();

         out.println("*******************<br />");

    }

   

}

 

 

customaction.tld 


<?xml version="1.0" encoding="UTF-8" ?>

<taglib xmlns="http://java.sun.com/xml/ns/j2ee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"

    version="2.0">

   

    <tlib-version>1.0</tlib-version>

    <short-name>tool</short-name>

     <tag>

         <name>startLine</name>

         <tag-class>customaction.StartLineTag</tag-class>

         <body-content>empty</body-content>

     </tag>

 

</taglib>

   

 

 

web.xml


<?xml version="1.0" encoding="ISO-8859-1"?>

 

<web-app 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-app_3_0.xsd"

  version="3.0"

  metadata-complete="true">

 

    <display-name>Welcome to Tomcat</display-name>

     <description>Welcome to Tomcat</description>

   

    <jsp-config>

    <taglib>

         <taglib-uri>/taglibs/customaction.tld</taglib-uri>

         <taglib-location>/WEB-INF/tlds/customaction.tld</taglib-location>

    </taglib>

    </jsp-config>

   

   

</web-app>

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<%@taglib prefix="tool" uri="/taglibs/customaction.tld" %>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

 

<h3>이달의 신착도서</h3>

<tool:startLine/>

멀티프로서서 프로그래밍<br />

트와일라잇<br />

회사에서 바로 통하는 관리 회계<br />

<tool:startLine/>

</body>

</html>