------------------------------------------------------------------
1.web.xml设置
</web-app>结束前输入
<jsp-config>
<taglib>
<taglib-uri>/tld/cy</taglib-uri>
<taglib-location>/WEB-INF/tlds/cy.tld</taglib-location>
</taglib>
</jsp-config>
------------------------------------------------------------------
2.在WEB-INF目录下创建tlds文件夹,在该文件加下创建cy.tld文件
cy.tld文件内容:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>cytag</short-name>
<tag>
<name>chData</name>
<tag-class>com.nbyt.commom.myTag.cyTag</tag-class>
<body-content>empty</body-content>
<!--attribute 属性-->
<attribute>
<name>key</name> 属性名称
<required>false</required> 是否必填
<rtexprvalue>true</rtexprvalue> 是否支持表达式值
</attribute>
</tag>
-------------------------------------------------------------------
3.创建cyTag 类
package com.nbyt.commom.myTag;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import com.nbyt.commom.pClass.PMA;
/**
* 取得中文的数字 一、二、三
*/
public class cyTag extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private int key;
public cyTag() {
}
@Override
public int doStartTag() throws JspException {
return EVAL_BODY_INCLUDE;
}
public int doEndTag() throws JspException {
try {
pageContext.getOut().write(PMA.initCnNumber().get(this.getKey()));
} catch (IOException ex) {
throw new JspException("错误");
}
return EVAL_PAGE;
}
public int getKey() {
return key;
}
public void setKey(int key) {
this.key = key;
}
}
</taglib>
------------------------------------------------------------------------------
PMA类中的方法
/**
* 初始化中文数字
*/
public static Hashtable<Integer, String> initCnNumber() {
Hashtable<Integer, String> ht = new Hashtable<Integer, String>();
ht.put(1, "一");
ht.put(2, "二");
ht.put(3, "三");
ht.put(4, "四");
ht.put(5, "五");
ht.put(6, "六");
ht.put(7, "七");
ht.put(8, "八");
ht.put(9, "九");
ht.put(10, "十");
return ht;
}