当前位置:网站首页>JSTL 自定义标签
JSTL 自定义标签
2022-06-11 13:48:00 【梁云亮】
说明
JSTL默认不支持LocalDate和LocalDateTime,在JSP中自定义显示LocalDate和LocalDateTime,需要通过自定义标签实现。
第一步:创建具体进行转换的工具类
- LocalDateTimeFormatter
public class LocalDateTimeFormatter {
public static String formatLocalDateTime(LocalDateTime localDateTime, String pattern) {
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
}
}
- LocalDateFormatter
public class LocalDateFormatter {
public static String formatLocalDate(LocalDate localDate, String pattern) {
return localDate.format(DateTimeFormatter.ofPattern(pattern));
}
}
第二步:在WEB-INF目录下创建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.0</tlib-version>
<short-name>Custom_Functions</short-name>
<uri>http://wego.com/format</uri>
<function>
<name>formatLocalDateTime</name>
<function-class>com.wego.formatter.LocalDateTimeFormatter</function-class>
<function-signature>java.lang.String formatLocalDateTime(java.time.LocalDateTime, java.lang.String)</function-signature>
</function>
<function>
<name>formatLocalDate</name>
<function-class>com.wego.formatter.LocalDateFormatter</function-class>
<function-signature>java.lang.String formatLocalDate(java.time.LocalDate, java.lang.String)</function-signature>
</function>
</taglib>
第三步:测试
- 服务器端数据
request.setAttribute("localDate", LocalDate.now());
request.setAttribute("localDateTime", LocalDateTime.now());
- 页面使用
日期:${
f:formatLocalDate(localDate, 'yyyy-MM*dd')}
日期时间:${
f:formatLocalDateTime(localDateTime, 'yyyy-MM-dd HH:mm:ss')}
边栏推荐
- tp6基于whoops的异常接管(漂亮的界面)
- Redis uses 10 tips, please accept!
- AGV robot RFID sensor ck-g06a and Siemens 1200plc Application Manual
- 基于FPGA的VGA协议实现
- 2022工具钳工(中级)操作证考试题库及答案
- RS485(Modbus RTU)工业RFID读写器CK-FR03-A01与PLC三菱FX5U的通讯操作说明
- tampermonkey这玩意如何替换flash播放器为h5播放器?
- Just after the college entrance examination, I was confused and didn't know what to do? Tell me what I think
- [201] PHP exception handling - try catch finally exception handling in PHP
- Ecplise cannot connect to SQL Server
猜你喜欢

Microsoft exposes another "scandal": watching VR porn in the office, "the father of hololens" is about to leave!

Learning notes of yolov3: model structure of yolov3

Container -- reverse content -- use of explosion, splicing, and inversion functions

YOLOv3学习笔记:YOLOv3的模型结构

On the life extension of distributed locks -- redis based distributed locks

Teatalk · online speech record | complete! It is important to select the right data migration strategy for safe cloud deployment

The end of an era! After ten years, Wu Enda's classic machine learning course closed its registration this month and launched a new course

Vi LXD deployment of lab server for development records

JSP实现银柜台业务绩效考核系统

How to write high-performance code (IV) optimize data access
随机推荐
How to learn to spend money
[backtrader source code analysis 46] cerebro Py code comments (boring, one of the core backtrader codes, recommended for reading, comments for reference only)
After five years of losing the lawsuit, the trillion reptile army is ready to move
In 2022, capture these 12 data and analyze trends!
The global mobile phone market is declining, and even apple does not expect too much of the iphone14
为什么每运行一部都显示一次数据库已存在,都要删除数据库,然后才能成功,每运行一部都要删除一次数据库,重新运行整体才成功.
看不懂Kotlin源码?从Contracts 函数说起~
Microsoft exposes another "scandal": watching VR porn in the office, "the father of hololens" is about to leave!
cadence SPB17.4 - allegro - allegro_free_viewer
cadence SPB17.4 - group operation(add to group, view group list, delete group)
C # set the cursor shape of forms and systems
Implementation of VGA protocol based on FPGA
cadence SPB17.4 - group operation(add to group, view group list, delete group)
Introduction to long connection
JDBC connection pool is used for batch import. 5million data are run each time, but various problems will occur in the middle
Introduction to common fonts
From real-time computing to streaming data warehouse, where will Flink go next?
Nomad application scheduling scheme 08 of hashicopy (detection job)
Each of D is inconsistent with the map
可变参表达式