NewLineTag.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 NewLineTag extends SimpleTagSupport {
private int size;
private String color;
public void setSize(int size) {
this.size = size;
}
public void setColor(String color) {
this.color = color;
}
@Override
public void doTag() throws JspException, IOException {
// TODO Auto-generated method stub
JspContext context = getJspContext();
JspWriter out = context.getOut();
out.println("<font color=" + color + ">");
for(int cnt=0 ; cnt<size ; cnt++){
out.println("*");
}
out.println("</font><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>
<tag>
<name>newLine</name>
<tag-class>customaction.NewLineTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>size</name>
<type>java.lang.Integer</type>
</attribute>
<attribute>
<name>color</name>
<type>java.lang.String</type>
</attribute>
</tag>
<tag>
<name>newerLine</name>
<tag-class>customaction.NewerLineTag</tag-class>
<body-content>empty</body-content>
<dynamic-attributes>true</dynamic-attributes>
</tag>
</taglib>
<%@ 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:newLine color="red" size="40"/>
카르멘(오페라) DVD <br />
돈키호테 (발레) DVD <br />
시간을 달리는 소녀(애니메이션)<br />
<tool:newLine color="red" size="40"/>
전자정보실에서만 감상하실 수 있습니다.<br />
<tool:newLine color="blue" size="50"/>
</body>
</html>
'JSP' 카테고리의 다른 글
본체가 있는 커스텀액션을 만드는 태그클래스 (0) | 2013.03.22 |
---|---|
애트리뷰트가 있는 커스텀액션을 만드는 태그클래스2 (0) | 2013.03.22 |
SimpleTagSupport 클래스를 이용해서 태그 클래스 작성 (0) | 2013.03.22 |
커스텀액션의 본체 안에서 변수 사용하기 (0) | 2013.03.22 |
변수를 지원하는 커스텀액션2 (0) | 2013.03.22 |