FontTagLib.tld
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>Exeample TLD</short-name>
<tag>
<name>font</name>
<tag-class>com.oraclejava.FontTag</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>size</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>face</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
</taglib>
FontTag.java
package com.oraclejava;
import java.io.IOException;
import java.io.StringWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class FontTag extends SimpleTagSupport {
private int size = 0; // 픽셀
private String face = ""; //글꼴
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String getFace() {
return face;
}
public void setFace(String face) {
this.face = face;
}
StringWriter sw = new StringWriter();
@Override
public void doTag() throws JspException, IOException {
// TODO Auto-generated method stub
super.doTag();
if(size == 0) size = 12;
if("".equals(face)) face="돋움";
getJspBody().invoke(sw);
getJspContext().getOut().println("<span style=\"font-size:"+size+
"px;font-family:" + face + "\">" + sw.toString() + "</span>"
);
}
FontTagLib.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="ex" uri="/WEB-INF/FontTagLib.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>A sample custom tag</title>
</head>
<body>
<ex:font face="궁서" size="50">갤럭시S8 화면크기 5.7인치...</ex:font>
</body>
</html>
'개발속이야기 > Java' 카테고리의 다른 글
JSP EL 예제 (0) | 2018.01.03 |
---|---|
JSP JDBC 설정 예제 (0) | 2018.01.03 |
이클립스 (Eclipse)에서 자동 들여쓰기 (Indentation) , Import 지우기 (0) | 2018.01.02 |
JSP TAG OlympicTag 예제 (0) | 2018.01.02 |
JSP TAG 메일 예제 (0) | 2018.01.02 |