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

xiaoxiao2022-06-12  78

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"> </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>
转载请注明原文地址: https://www.6miu.com/read-4932681.html

最新回复(0)