利用SimpleTagSupport接口自定义标签
来源:互联网 发布:淘宝网保安服装 编辑:程序博客网 时间:2024/06/11 17:06
·控制jsp页面某一部分内容是否执行
java代码:
package cn.itcast.web.simpletag;import java.io.IOException;import javax.servlet.jsp.JspContext;import javax.servlet.jsp.JspException;import javax.servlet.jsp.tagext.JspFragment;import javax.servlet.jsp.tagext.SimpleTagSupport;//控制标签体是否执行public class SimpleTagDemo1 extends SimpleTagSupport {@Overridepublic void doTag() throws JspException, IOException {JspFragment jf = this.getJspBody();jf.invoke(this.getJspContext().getOut()); //标签体执行super.doTag();}}
tld代码:
<tag> <name>demo1</name> <tag-class>cn.itcast.web.tag.SimpleTagDemo1</tag-class> <body-content>scriptless</body-content> <!-- script代表有标签体 scriptless是无脚本 --></tag>jsp中代码:
声明:
<%@ taglib uri="/simpletag" prefix="sitcast" %>调用:
<sitvast:demo1>aaaa<br/></sitvast:demo1>
·用简单标签体实现迭代
java代码:
package cn.itcast.web.simpletag;import java.io.IOException;import javax.servlet.jsp.JspException;import javax.servlet.jsp.tagext.JspFragment;import javax.servlet.jsp.tagext.SimpleTagSupport;public class SimpleTagDemo2 extends SimpleTagSupport {@Overridepublic void doTag() throws JspException, IOException {JspFragment jf = this.getJspBody();for(int i = 0; i < 5; i++){jf.invoke(null); //null是默认写给浏览器 相当于:jf.invoke(this.getJspContext().getOut());}}}
tld声明代码:
<tag> <name>demo2</name> <tag-class>cn.itcast.web.simpletag.SimpleTagDemo2</tag-class> <body-content>scriptless</body-content> <!-- script代表有标签体 scriptless是无脚本 --></tag>jsp中的代码:
声明:
<%@ taglib uri="/simpletag" prefix="sitcast" %>
调用:
<sitcast:demo2> This is my JSP page. <br> </sitcast:demo2>
实现效果:
输出五次This is my JSP page.
·将标签内容改为大写
java代码:
package cn.itcast.web.simpletag;import java.io.IOException;import java.io.StringWriter;import javax.servlet.jsp.JspException;import javax.servlet.jsp.tagext.JspFragment;import javax.servlet.jsp.tagext.SimpleTagSupport;public class SimpleTagDemo3 extends SimpleTagSupport {@Overridepublic void doTag() throws JspException, IOException {JspFragment jf = this.getJspBody();StringWriter sw = new StringWriter();jf.invoke(sw);String content = sw.toString();content = content.toUpperCase();this.getJspContext().getOut().write(content);}}
tld声明代码:
<tag> <name>demo3</name> <tag-class>cn.itcast.web.simpletag.SimpleTagDemo3</tag-class> <body-content>scriptless</body-content> <!-- script代表有标签体 scriptless是无脚本 --></tag>
jsp中的代码:
声明:
<%@ taglib uri="/simpletag" prefix="sitcast" %>调用:
<sitcast:demo3> This is my JSP page. <br></sitcast:demo3>
0 0
- 利用SimpleTagSupport接口自定义标签
- 利用 SimpleTagSupport 开发自定义标签
- 利用 SimpleTagSupport 开发自定义标签
- 利用 SimpleTagSupport 开发自定义标签
- 利用 JSP 2 提供的 SimpleTagSupport 开发自定义标签
- 利用 JSP 2 提供的 SimpleTagSupport 开发自定义标签
- 利用 JSP 2 提供的 SimpleTagSupport 开发自定义标签
- 利用 JSP 2 提供的 SimpleTagSupport 开发自定义标签
- 利用JSP2提供的SimpleTagSupport 开发自定义标签
- 利用 JSP 2 提供的 SimpleTagSupport 开发自定义标签
- 利用 JSP 2 提供的 SimpleTagSupport 开发自定义标签
- 利用 JSP 2 提供的 SimpleTagSupport 开发自定义标签
- 利用 JSP 2 提供的 SimpleTagSupport 开发自定义标签
- 利用SimpleTagSupport创建定制标签
- SimpleTagSupport自定义标签的使用
- 用SimpleTagSupport类开发自定义标签
- JSTL自定义标签二SimpleTagSupport(一)
- JSTL自定义标签二SimpleTagSupport(二)
- 【C语言】模拟用户登录系统 以及演示多个字符从两端向中间靠拢
- 装配Bean(五)
- hdu1176 免费馅饼 动态规划 二维数组实现
- 连连看(广搜)
- 什么是iNAND,iNAND有什么优点
- 利用SimpleTagSupport接口自定义标签
- scala 类定义构造函数与继承
- 洛谷 P1757 通天之分组背包
- Android四大组件之三:BroadcastReceiver总结
- 大数据概述
- 监听器(Listener)学习
- NKOI 3500 独立集
- Android笔记:自定义控件-is not using the 2- or 3-argument Vieconstructors; XML attributes will not work
- canvas画布变换画六芒星