jstl标签基础开发步骤(详解)
作者:jingxian 时间:2023-07-08 18:25:41
step1. 导包(导入要使用的标签的jar文件)。
step2. 使用taglib指令引入要使用的标签。
taglib指令:
uri:标签的命名空间。
prefix:命名空间的别名。
注:
命名空间:是为了区分同名的元素而添加的前缀。
自定义标签:
step1. 写一个java类,继承SimpleTagSupport类。
step2. 在doTag方法里面,编写处理逻辑。
step3. 描述标签。(.tld文件里面)
注: <body-content>的值可以是
empty 没有标签体。
scriptless 可以有标签体,但是标签体的内容不能够出现java代码。
JSP 可以有标签体,标签体的内容可以出现java代码。(只有复杂标签技术才支持JSP这个值,简单标签技术只支持empty和scriptless)。
简单日期标签datetag.tld例:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<tlib-version>1.1</tlib-version>
<short-name>d1</short-name>
<uri>http://aliyun.com</uri>
<tag>
<!-- name:表示自定义标签 <c1:date名字相同 -->
<name>date</name>
<tag-class>tag.DateTag</tag-class>
<body-content>empty</body-content>
<attribute>
<!-- name:表示自定义标签 <c1:date datetag名字相同 -->
<name>datetag</name>
<!-- true,表示可以使用el表达式来赋值 -->
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
</taglib>
日期java标签类:
package tag;
/**
* 自定义日期标签
*/
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class DateTag extends SimpleTagSupport {
private String datetag;
public String getDatetag() {
return datetag;
}
public void setDatetag(String datetag) {
this.datetag = datetag;
}
@Override
public void doTag() throws JspException, IOException {
PageContext pc = (PageContext) getJspContext();
SimpleDateFormat sdf = new SimpleDateFormat(datetag);
String date = sdf.format(new Date());
JspWriter out = pc.getOut();
out.println(date);
}
}
标签:jstl,标签
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java实现文件变化监控的方法(推荐)
2023-11-08 01:18:26
c#动态调用Webservice的两种方法实例
2021-09-19 20:12:05
ibatis学习之搭建Java项目
2021-11-02 00:35:29
Java去重排序之Comparable与Comparator的使用及说明
2023-04-28 00:49:27
![](https://img.aspxhome.com/file/2023/8/122278_0s.png)
Android之复选框对话框用法实例分析
2023-10-03 05:07:03
![](https://img.aspxhome.com/file/2023/1/84751_0s.png)
如何基于JavaFX开发桌面程序
2023-10-30 11:06:19
新手小白学JAVA IDEA下载使用手册全集
2023-11-23 14:33:23
![](https://img.aspxhome.com/file/2023/3/59773_0s.jpg)
SpringBoot遇到的坑@Qualifier报红的解决
2022-06-03 07:49:55
![](https://img.aspxhome.com/file/2023/5/66965_0s.png)
SpringCloud微服务基础简介
2022-09-01 23:16:24
![](https://img.aspxhome.com/file/2023/0/132080_0s.png)
详解JAVA 弱引用
2022-03-12 01:30:29
Android播放音乐案例分享
2023-08-27 14:41:31
![](https://img.aspxhome.com/file/2023/7/139447_0s.jpg)
maven手动上传jar包示例及图文步骤过程
2023-11-13 22:10:57
![](https://img.aspxhome.com/file/2023/1/59571_0s.png)
java报错:找不到或无法加载主类的解决方法简单粗暴
2023-03-29 17:20:58
![](https://img.aspxhome.com/file/2023/4/93074_0s.png)
Mybatis逆工程jar包的修改和打包
2023-06-03 09:28:14
![](https://img.aspxhome.com/file/2023/7/119127_0s.png)
Android 使用Picasso加载网络图片等比例缩放的实现方法
2023-08-29 15:36:32
C#控件Picturebox实现鼠标拖拽功能
2021-10-30 20:52:36
C#实现图片上传(PC端和APP)保存及 跨域上传说明
2022-11-10 17:05:11
![](https://img.aspxhome.com/file/2023/8/108928_0s.png)
executor包执行器功能
2023-07-26 21:07:36
C# Winform消息通知系统托盘气泡提示框ToolTip控件
2023-01-13 23:31:02
![](https://img.aspxhome.com/file/2023/5/68075_0s.jpg)
简单掌握Android Widget桌面小部件的创建步骤
2021-12-07 01:48:35