自定义标签学习与经验教训1

regtld/Protld.java
 
package regtld;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspWriter;
import properties.RegProperties;
public class Protld extends TagSupport {
 private String temp;
 public void setTemp(String temp){
  this.temp=temp;
 }
 public int doEndTag() throws JspException {
  // TODO 自动生成方法存根
  JspWriter out=pageContext.getOut();
  try{
//new RegProperties().getProperties(temp)自定义的一个从register.properties文件中读取数据的类方法
   out.print(new RegProperties().getProperties(temp));
  }catch(Exception e){
   System.err.println(e);
  }
  return super.doEndTag();
 } 
}
 
foot.jsp
 
< %@page pageEncoding="GB2312"%>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< %@taglib uri="/reg" prefix="reg" %>
<table width="800" border="1" align="center" bordercolor="#FF9900">
  <tr>
    <td height="20" bgcolor="#FF9900">&nbsp;</td>
  </tr>
  <tr>
    <td height="100" align="center" valign="middle" bgcolor="#F0F0F0"><p>版权所有:
      <reg:protld temp="copyright" /></p>
    <p>技术支持:<reg:protld temp="designer" /></p></td>
  </tr>
</table>
 
 
web.xml
 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
 <display-name>Register</display-name>
 <description>design by xiang</description>

 <welcome-file-list>
  <welcome-file>/index.jsp</welcome-file>
 </welcome-file-list>
 
 <session-config>
  <session-timeout>30</session-timeout>
 </session-config>
 
 <taglib>
  <taglib-uri>/reg</taglib-uri>
  <taglib-location>/WEB-INF/tld/reg.tld</taglib-location>
 </taglib>
</web-app>

标签库reg.tld
 
<?xml version="1.0" encoding="UTF-8"?>
<!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>tld</short-name>
 <uri>/reg</uri>
 <tag>
  <name>protld</name>
  <tagclass>regtld.Protld</tagclass>
  <bodycontent>empty</bodycontent>
  <info>Display title</info>
  <attribute>
   <name>temp</name>
   <required>true</required>
   <rtexprvalue>false</rtexprvalue>
   <type>String</type>
  </attribute>
 </tag>
</taglib>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值