NewerLineTag.java
package customaction;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.DynamicAttributes;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class NewerLineTag extends SimpleTagSupport implements DynamicAttributes{
private Map<String,Object> attrs = new HashMap<String,Object>();
@Override
public void setDynamicAttribute(String uri, String localName, Object value)
throws JspException {
// TODO Auto-generated method stub
attrs.put(localName, value);
}
@Override
public void doTag() throws JspException, IOException {
// TODO Auto-generated method stub
String color = (String) attrs.get("color");
int size = Integer.parseInt((String) attrs.get("size"));
JspContext context = getJspContext();
JspWriter out = context.getOut();
out.println("<font color=" + color + ">");
for(int cnt=0 ; cnt<size ; cnt++){
out.print("*");
}
out.println("</font><br />");
return;
}
}
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:newerLine color="red" size="40" background="black"/>
제목:폴라 익스프레스<br />
일시 : 2009년 7월 4일 (토) 오후 5:00 <br />
<tool:newerLine color="blue" size="45" height="3"/>
</body>
</html>
'JSP' 카테고리의 다른 글
커스텀액션의 본체 내용을 조작하는 태그클래스 (0) | 2013.03.22 |
---|---|
본체가 있는 커스텀액션을 만드는 태그클래스 (0) | 2013.03.22 |
애트리뷰트가 있는 커스텀액션을 만드는 태그클래스1 (0) | 2013.03.22 |
SimpleTagSupport 클래스를 이용해서 태그 클래스 작성 (0) | 2013.03.22 |
커스텀액션의 본체 안에서 변수 사용하기 (0) | 2013.03.22 |