博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JSP自定义tag控件标签
阅读量:4314 次
发布时间:2019-06-06

本文共 2394 字,大约阅读时间需要 7 分钟。

JSP支持自定tag的方法,那就是直接讲JSP代码保存成*.tag或者*.tagx的标签定义文件。tag和tagx文件不仅支持经典jsp代码,各种标签模版代码,还支持xml样式的jsp指令代码。

按照约定,tag和tagx文件需要放置在WEB-INF/tags目录下。

 

下面是一个简单的例子,使用自定义标签创建一个Button:

1 <%@ tag language="java" pageEncoding="UTF-8"%> 2 <%@ include file="/webpage/include/taglib.jsp"%> 3 <%@ attribute name="id" type="java.lang.String" required="true"%> 4 <%@ attribute name="url" type="java.lang.String" required="true"%> 5 <%@ attribute name="title" type="java.lang.String" required="true"%> 6 <%@ attribute name="width" type="java.lang.String" required="false"%> 7 <%@ attribute name="height" type="java.lang.String" required="false"%> 8 <%@ attribute name="target" type="java.lang.String" required="false"%> 9 <%@ attribute name="label" type="java.lang.String" required="false"%>10 11                         12 <%-- 使用方法: 1.将本tag写在查询的form之前;2.传入table的id和controller的url --%>13 

 

在页面中使用标签:

 

标签文件中常用的指令:

 

tag 类似JSP page指令,可以用于import常用的java类库等
include 导入其他的标签定义文件
taglib 使用其他标签,如jstl, spring tag, struts tag等等
attribute 定义一个属性
variable 定义一个jsp page中可见的变量,默认范围为NESTED,表示标签内有效。可选项有AT_BEGIN和AT_END

这些指令的可选属性:

body-content 标签body的处理方式 ,可选项: 'empty', 'tagdependent' or 'scriptless'
import 导入使用的java类库
pageEncoding 设置页面编码
isELIgnored 是否忽略el表达式
dynamic-attributes 用于存储自定义属性的map,所谓的自定义属性指:未隐式申明的变量
language 使用的脚本语言,目前必须是java
display-name 标签名
small-icon for tools
large-icon for tools
description 标签作用描述
example informal description of how the tag is used

 

<jsp:directive:attribute>的可选属性:

name 属性名
required true or false,是否是必须的
rtexprvalue true or false - 指定是否支持运行时表达式
type 值类型 - 默认是java.lang.String
fragment true or false - 值先传递给容器(false), 直接传给标签处理方法(true)
description 属性描述

 

<jsp:directive:variable>的可选属性:

name-given 变量名(标签使用时的变量名)
name-from-attribute Specifies the name of an attribute, whose value is the name of the variable that will be available in the calling JSP page. Exactly one of name-given or name-from-attribute must be supplied.
alias A locally scoped variable which will store the variable's value. Used only with name-from-attribute.
variable-class 变量类.默认是java.lang.String.
declare Indicates whether the variable is declared in the calling JSP page or tag file. Default is true. Not entirely clear what this means!
scope 变量范围,可选项 AT_BEGIN(标签后jsp page内有效), AT_END(标签后jsp page内有效) and NESTED. NESTED(默认,标签内有效)
description 变量描述

转载于:https://www.cnblogs.com/qingo00o/p/8989787.html

你可能感兴趣的文章
python3 序列分片记录
查看>>
Atitit.git的存储结构and 追踪
查看>>
atitit 读书与获取知识资料的attilax的总结.docx
查看>>
B站 React教程笔记day2(3)React-Redux
查看>>
找了一个api管理工具
查看>>
Part 2 - Fundamentals(4-10)
查看>>
使用Postmark测试后端存储性能
查看>>
NSTextView 文字链接的定制化
查看>>
第五天站立会议内容
查看>>
CentOs7安装rabbitmq
查看>>
(转))iOS App上架AppStore 会遇到的坑
查看>>
解决vmware与主机无法连通的问题
查看>>
做好产品
查看>>
项目管理经验
查看>>
笔记:Hadoop权威指南 第8章 MapReduce 的特性
查看>>
JMeter响应数据出现乱码的处理-三种解决方式
查看>>
获取设备实际宽度
查看>>
Notes on <High Performance MySQL> -- Ch3: Schema Optimization and Indexing
查看>>
Alpha冲刺(10/10)
查看>>
数组Array的API2
查看>>