-
自定义标签
2016-05-09 23:33:50 -
java自定义标签java自定义标签java自定义标签
2010-11-12 19:57:54java自定义标签java自定义标签java自定义标签java自定义标签java自定义标签java自定义标签 -
自定义标签
2006-10-03 20:37:00自定义标签 =========自定义标签学习总结========= 标签的运行方式是:JSP页面解析中发现自定义标签,则到上面的标签说明中寻找:如@ taglib uri="/mytitle.tld" prefix="dada"%>此时它会找到该标签的uri ,uri ...=========自定义标签学习总结=========
标签的运行方式是:
JSP页面解析中发现自定义标签,则到上面的标签说明中寻找:如
<%@ taglib uri="/mytitle.tld" prefix="dada"%>
<taglib>
<taglib-uri>/mytitle.tld</taglib-uri>
<taglib-location>/WEB-INF/mytitle.tld</taglib-location>
</taglib>
<name>title</name>
<tagclass>com.derek.tags.TitleTag</tagclass>
准备工作 :首先在WEB-INF/lib下添加taglibs-log.jar包
1、创建标签描述文件
在WEB-INF下新建一个tld文件,该文件描述了此tld文件将由那个处理类完成操作,并且定义了该标签的属性。一个<taglib>中可以有很多个<tag>,由<name>标签名区分。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>html</shortname>
<uri>http://jakarta.apache.org/struts/tags-html</uri>
<tag>
<name>title</name>
<tagclass>com.derek.tags.TitleTag</tagclass>
<bodycontent>empty</bodycontent>
<attribute>
<name>begin</name>
<required>true</required>
</attribute>
<attribute>
<name>end</name>
<required>true</required>
</attribute>
</tag>
</taglib>
2、创建标签处理类
该类继承 TagSupport,覆盖doEndTag()方法
package com.derek.tags;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspException;
import java.util.Properties;
import java.io.*;
import javax.servlet.jsp.JspWriter;
public class TitleTag extends TagSupport {
private String begin = null;
private String end = null;
public TitleTag() {}
public String getBegin() {return begin;}
public void setBegin(String begin) {this.begin = begin;}
public String getEnd(){return end;}
public void setEnd(String end){this.end = end;}
public int doEndTag() throws JspException {
Properties ps = (Properties)pageContext.getAttribute("ps",pageContext.APPLICATION_SCOPE);//从上下文中取的message.properties
JspWriter jw = pageContext.getOut();
if(begin!=null&&begin.length()>0){
String header = ps.getProperty(begin);
System.out.println("页眉"+begin);
try {
jw.println(header);
}catch (IOException ex) {ex.printStackTrace();}
}
if(end!=null&&end.length()>0){
String footer = ps.getProperty(end);
System.out.println(" 页脚"+end);
try {
jw.println(footer);
}catch (IOException ex1) {ex1.printStackTrace();}
}
return SKIP_BODY;
}
public void release() {
super.release();
}
}
3、修改web.xml文件
在web.xml中<web-app>下添加,将标签的uri与具体标签描述文件绑定
<taglib>
<taglib-uri>/mytitle.tld</taglib-uri>
<taglib-location>/WEB-INF/mytitle.tld</taglib-location>
</taglib>
4、在页面中使用标签
首先在页面中导入标签
<%@ taglib uri="/mytitle.tld" prefix="dada"%>
然后就可以在页面中使用了
<dada:title begin="" end="footer"/> -
JSP 自定义标签
2021-01-08 22:45:42JSP 自定义标签 自定义标签是用户定义的JSP语言元素。当JSP页面包含一个自定义标签时将被转化为servlet,标签转化为对被 称为tag handler的对象的操作,即当servlet执行时Web container调用那些操作。 JSP标签扩展... -
jsp自定义标签_JSP自定义标签
2020-07-30 07:41:23jsp自定义标签 JSP自定义标签 (JSP Custom Tag) When EL and Standard Action elements aren't enough to remove scriptlet code from your JSP Page, you can use Custom Tags. Custom tags are nothing but user-...jsp自定义标签
When EL and Standard Action elements aren't enough to remove scriptlet code from your JSP Page, you can use Custom Tags. Custom tags are nothing but user-defined tags.
当EL和标准动作元素不足以从JSP页面删除scriptlet代码时,可以使用“定制标记”。 自定义标签不过是用户定义的标签。
Custom tags are an excellent way to abstract the complexity of business logic from the presentation of Web pages in a way that is easy for the Web author to use and control. It also allows for reusability as custom tags can be used again and again.
自定义标记是一种以Web作者易于使用和控制的方式从网页的呈现中抽象出业务逻辑复杂性的极好方法。 由于自定义标签可以一次又一次地使用,因此它也允许重用。
JSP自定义标签的格式 (Format of JSP Custom tag)
The format of a custom tag can either be empty, called an Empty tag, or can contain a body, called a Body tag. The number of attributes that a tag will accept depends on the implementation of the Tag Handler class.
自定义标签的格式可以为空(称为Empty标签),也可以包含正文(称为Body标签)。 标签将接受的属性数量取决于Tag Handler类的实现。
Syntax for an Empty Tag is:
空标签的语法是:
<tagLibraryPrefix:customTagName attribute1="attributeName" attribute2="attributeName" ... />
The Syntax for a Custom Body Tag is :
自定义正文标签的语法为:
<tagLibraryPrefix:customTagName attribute1="attributeName" attribute2="attributeName" ... /> < --Body of custom tag-- > </tagLibraryPrefix:customTagName>
Creating custom tags is considered as a very good practice in JSP world. Always try to create and use your own custom tags from frequently used operations in your JSP application. Let's move to the next lesson and study how to create a Custom tag.
在JSP世界中,创建定制标记被认为是一种很好的做法。 始终尝试通过JSP应用程序中经常使用的操作来创建和使用自己的定制标记。 让我们进入下一课,学习如何创建自定义标签。
jsp自定义标签
-
react路由
-
我写的PE格式查看软件 仿PEiD.zip
-
第3章 入门程序、常量、变量
-
基于solidworks中的stewart平台建模
-
Digital+Camera+Utility+5.zip
-
【数据分析实战训练营】Hive详解
-
UnitySocket异步聊天室
-
【数据分析-随到随学】Python数据获取
-
linux基础
-
中国矿业大学程序设计综合实践代码.zip
-
转行做IT-第7章 数组
-
Python入门到项目直通车
-
LoRaMac-node-3.4.1.zip
-
【踩雷血泪总结】torchvision加载EMNIST数据集方法 完美解决缺少train.pt和Dataset not found问题
-
C++异步串口通信
-
python 爬取数据(CBA所有球队数据) -爬虫
-
JavaEE框架(Maven+SSM)全程实战开发教程(源码+讲义)
-
信息系统项目管理师考前必做650题.pdf
-
BUUCTF 10
-
【数据分析-随到随学】Tableau数据分 析+PowerBI