jsp自定义标签开发

不处理体内容的标签理解一下图片1

 

处理体内容标签理解提图片2

 

 

1:JspWriter out = pageContext.getOut();

 

2:BodyContent bc = this.getBodyContent();
 3:String input = bc.getString();
 4:JspWriter out = bc.getEnclosingWriter();

 

不处理体内容

第一行代码为不处理标签体内容时拿到需要的输出到页面的对象

 

处理体内容

第二行代码为处理标签提内容时拿到包装了提内容信息的对象

第三行代码为拿出体内容。

第四行为拿到页面输出对象。

 

 

拿到对象后用out.print方法输出处理后的效果给页面

 

 

编写标记配置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">
 <description>test tag</description>
 <tlib-version>1.0</tlib-version>
 <short-name>util</short-name>
 <uri>/timeTage</uri>


 <tag>
  <description>fist tag</description>
  <name>Showtime</name>
  <tag-class>com.test.tag.TimeTag</tag-class>
  <body-content>JSP</body-content>
 </tag>

 <tag>
  <description>dateformat</description>
  <name>formatTime</name>
  <tag-class>com.test.tag.TimeFormat</tag-class>
  <body-content>empty</body-content>
  <attribute>
   <name>date</name>
   <required>false</required>
   <rtexprvalue>true</rtexprvalue>
  </attribute>
  <attribute>
   <name>pattern</name>
   <required>false</required>
   <rtexprvalue>false</rtexprvalue>
  </attribute>
 </tag>

 页面中需要:<%@taglib prefix="time" uri="/timeTage" %> 来引用

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值