现象&背景:

  异常:

    "org.apache.jasper.JasperException: 在 [115] 行处理 [/WEB-INF/jsp/modules/receivedyaccnotify/receive_dy_acc_notify.jsp] 时发生异常"
  代码:
    <%@ taglib prefix= "fmt" uri= "http://java.sun.com/jsp/jstl/fmt" %>
    <td><fmt:formatDate value= "${record.transTime}" pattern= "yyyy-MM-dd HH:mm:ss" type= "date" /></td>

原因:

  关于这个异常的详细说明,可以参考【https://blog.csdn.net/lzf_hlh/article/details/81737222】,这次的异常发生的原因是类型转换导致的:即因为${record.transTime}取出来是String类型,无法转换为Date类型。

详解:

  从代码中进入【fmt:formatDate】的JSTL源代码中可以发现以下描述(红色字体):

  【Date and/or time to be formatted.】:需要转换的value得是Date对象类型

  【Name of the exported scoped variable which stores the formatted result as a String.】:返回的值是String类型

 1 <tag>
2 <description>
3 Formats a date and/or time using the supplied styles and pattern
4 </description>
5 <name>formatDate</name>
6 <tag-class>org.apache.taglibs.standard.tag.rt.fmt.FormatDateTag</tag-class>
7 <body-content>empty</body-content>
8 <attribute>
9 <description>
10 Date and/or time to be formatted.
11 </description>
12 <name>value</name>
13 <required>true</required>
14 <rtexprvalue>true</rtexprvalue>
15 </attribute>
16 <attribute>
17 <description>
18 Specifies whether the time, the date, or both
19 the time and date components of the given
20 date are to be formatted.
21 </description>
22 <name>type</name>
23 <required>false</required>
24 <rtexprvalue>true</rtexprvalue>
25 </attribute>
26 <attribute>
27 <description>
28 Predefined formatting style for dates. Follows
29 the semantics defined in class
30 java.text.DateFormat. Applied only
31 when formatting a date or both a date and
32 time (i.e. if type is missing or is equal to
33 "date" or "both"); ignored otherwise.
34 </description>
35 <name>dateStyle</name>
36 <required>false</required>
37 <rtexprvalue>true</rtexprvalue>
38 </attribute>
39 <attribute>
40 <description>
41 Predefined formatting style for times. Follows
42 the semantics defined in class
43 java.text.DateFormat. Applied only
44 when formatting a time or both a date and
45 time (i.e. if type is equal to "time" or "both");
46 ignored otherwise.
47 </description>
48 <name>timeStyle</name>
49 <required>false</required>
50 <rtexprvalue>true</rtexprvalue>
51 </attribute>
52 <attribute>
53 <description>
54 Custom formatting style for dates and times.
55 </description>
56 <name>pattern</name>
57 <required>false</required>
58 <rtexprvalue>true</rtexprvalue>
59 </attribute>
60 <attribute>
61 <description>
62 Time zone in which to represent the formatted
63 time.
64 </description>
65 <name>timeZone</name>
66 <required>false</required>
67 <rtexprvalue>true</rtexprvalue>
68 </attribute>
69 <attribute>
70 <description>
71 Name of the exported scoped variable which
72 stores the formatted result as a String.
73 </description>
74 <name>var</name>
75 <required>false</required>
76 <rtexprvalue>false</rtexprvalue>
77 </attribute>
78 <attribute>
79 <description>
80 Scope of var.
81 </description>
82 <name>scope</name>
83 <required>false</required>
84 <rtexprvalue>false</rtexprvalue>
85 </attribute>
86 </tag>

  因为从数据库读取的字段为字符串格式的"20230321165837",通过【fmt:formatDate】转换的时候以致发生异常。

  所以在调用之前将所需要转换的项目变成Date类型,那么可以通过【fmt:parseDate】进行转换解析,参考代码如下:

1 <td>
2 <fmt:parseDate value="${record.transTime}" var="trade_Date" pattern="yyyyMMddHHmmss" type="date"/> //yyyyMMddHHmmss见补充说明※1.
3 <fmt:formatDate value="${trade_Date}" pattern="yyyy-MM-dd HH:mm:ss" type="date"/> //yyyy-MM-dd HH:mm:ss见补充说明※2.
4 </td>

  补充说明:

  ※1.关于【yyyyyMMddHHmmss】:与转换的日期字符串的格式一致,否则可能回报【value attribute can not be parsed: "20230321165837"】错误。

    示例1:

    日期字符串:"20230321165837:

    转换格式:"yyyyyMMddHHmmss"

    示例2:

    日期字符串:"2023/03/21 16:58:37"

    转换格式:"yyyy/MM/dd HH:mm:ss"

  ※2.关于【yyyy-MM-dd HH:mm:ss】:这个可以是任意

  ※3.关于【fmt:parseDate】的入值与出值的类型说明:

  【Date string to be parsed.】:需要转换的value得是日期字符串

  【Name of the exported scoped variable in which the parsing result (of type java.util.Date) is stored.】:返回的值是java.util.Date类型

  1 <tag>
2 <description>
3 Parses the string representation of a date and/or time
4 </description>
5 <name>parseDate</name>
6 <tag-class>org.apache.taglibs.standard.tag.rt.fmt.ParseDateTag</tag-class>
7 <body-content>JSP</body-content>
8 <attribute>
9 <description>
10 Date string to be parsed.
11 </description>
12 <name>value</name>
13 <required>false</required>
14 <rtexprvalue>true</rtexprvalue>
15 </attribute>
16 <attribute>
17 <description>
18 Specifies whether the date string in the
19 value attribute is supposed to contain a
20 time, a date, or both.
21 </description>
22 <name>type</name>
23 <required>false</required>
24 <rtexprvalue>true</rtexprvalue>
25 </attribute>
26 <attribute>
27 <description>
28 Predefined formatting style for days
29 which determines how the date
30 component of the date string is to be
31 parsed. Applied only when formatting a
32 date or both a date and time (i.e. if type
33 is missing or is equal to "date" or "both");
34 ignored otherwise.
35 </description>
36 <name>dateStyle</name>
37 <required>false</required>
38 <rtexprvalue>true</rtexprvalue>
39 </attribute>
40 <attribute>
41 <description>
42 Predefined formatting styles for times
43 which determines how the time
44 component in the date string is to be
45 parsed. Applied only when formatting a
46 time or both a date and time (i.e. if type
47 is equal to "time" or "both"); ignored
48 otherwise.
49 </description>
50 <name>timeStyle</name>
51 <required>false</required>
52 <rtexprvalue>true</rtexprvalue>
53 </attribute>
54 <attribute>
55 <description>
56 Custom formatting pattern which
57 determines how the date string is to be
58 parsed.
59 </description>
60 <name>pattern</name>
61 <required>false</required>
62 <rtexprvalue>true</rtexprvalue>
63 </attribute>
64 <attribute>
65 <description>
66 Time zone in which to interpret any time
67 information in the date string.
68 </description>
69 <name>timeZone</name>
70 <required>false</required>
71 <rtexprvalue>true</rtexprvalue>
72 </attribute>
73 <attribute>
74 <description>
75 Locale whose predefined formatting styles
76 for dates and times are to be used during
77 the parse operation, or to which the
78 pattern specified via the pattern
79 attribute (if present) is applied.
80 </description>
81 <name>parseLocale</name>
82 <required>false</required>
83 <rtexprvalue>true</rtexprvalue>
84 </attribute>
85 <attribute>
86 <description>
87 Name of the exported scoped variable in
88 which the parsing result (of type
89 java.util.Date) is stored.
90 </description>
91 <name>var</name>
92 <required>false</required>
93 <rtexprvalue>false</rtexprvalue>
94 </attribute>
95 <attribute>
96 <description>
97 Scope of var.
98 </description>
99 <name>scope</name>
100 <required>false</required>
101 <rtexprvalue>false</rtexprvalue>
102 </attribute>
103 </tag>

JSTL标签fmt:formatDate格式化日期出错的更多相关文章

  1. JSP标签 <fmt:formatDate>格式化日期

    <fmt:formatDate>标签用于使用不同的方式格式化日期. <%@ page language="java" contentType="text ...

  2. jstl标签的fmt:formatDate格式化日期 String to Date

    使用fmt函数需在jsp中引入 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" ...

  3. jsp页面格式化时间 fmt:formatDate格式化日期

    使用fmt函数需在jsp中引入 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" ...

  4. Jsp页显示时间标签JSTL标签 <fmt:formatDate/> 实例大全

    <fmt:formatDate value="${isoDate}" type="both"/>2004-5-31 23:59:59 <fmt ...

  5. 日期格式化标签<fmt:formatDate>&<fmt:setTimeZone>时区标签的使用demo

    日期格式化标签<fmt:formatDate>&<fmt:setTimeZone>时区标签的使用demo <%@ page contentType="t ...

  6. fmt标签把时间戳格式化日期

    jsp页面标签格式化日期 <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %> ...

  7. 在EL表达式或者Struts标签库中格式化日期对象,即将Date转换为yyyy-MM-dd格式

    一.EL表达式 首先,在jsp页面引入<fmt> tags,<%@ taglib prefix="fmt" uri="http://java.sun.c ...

  8. formatDate() 格式化日期

    function datefmt(milSec, format) { var oldTime = Number(milSec); //得到毫秒数 // 日期格式转换 var t = new Date( ...

  9. JavaWeb基础Day17 (JSP EL表达式 jstl标签库 beanutil工具类)

    JSP jsp的实质就是指在html界面中嵌入Java代码 jsp脚本 <%  Java代码  %>  相当于写在service方法中. <%=java 变量或者表达式 %> ...

  10. Java Web程序设计笔记 • 【第10章 JSTL标签库】

    全部章节   >>>> 本章目录 10.1 JSTL 概述 10.1.1 JSTL 简介 10.1.1 JSTL 使用 10.1.2 实践练习 10.2 核心标签库 10.2. ...

随机推荐

  1. 使用bat脚本判断远程SVN文件是否有修改

    在Windows上, 使用 svn status -u -q %dir% 可以列出svn仓库的状态: M 8295 build.bat * 8306 E:\game\bzk\dev\tools\pro ...

  2. java 操作excel

    需要引入的包 import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.usermodel.HorizontalAlignmen ...

  3. 狐漠漠养成日记 Cp.00000 前言

    前言 狐漠漠是我的常用网名,来源是因为我非常非常非常喜欢耳廓狐(也称作沙漠狐),所以我就给自己拟造了一个名叫狐漠漠的虚拟形象(如下图所示). 设定上是女孩子因为我想当女孩子但是我不是所以我就在设定上满 ...

  4. idea中ueditor的入门

    首先在https://github.com/fex-team/ueditor下载ueditor1_4_3_3-utf8-jsp.zip:解压去掉里边jsp中的bin目录放到项目中的webapp中: 添 ...

  5. VUE-使用touchstart、touchmove、touchend实现拖拽卡片列表,实现更新排序功能

    感谢本文参考地址,原文解析更加清晰如有需要请移步:https://blog.csdn.net/weixin_40400844/article/details/114849253 怕原链接失效,将代码拷 ...

  6. 字节过滤流->缓冲流 BufferedOutputStream 用法:

    1创建字节输出节点流 :FileoutputStream fos = new FileoutputStream("文件输入的路径",true);(true表示追加,false表示覆 ...

  7. airtest的手势滑动方法封装

    ​ 这个网上应该很多类似的方法封装,各种实现方式也很多,但是感觉最简单实用的还是swipe了:代码很简单,直接上方法了. 很多方法都不会告诉你会导入什么包,其实很多小白入门可能就是这么简单的一步就被卡 ...

  8. 实验一Linux系统与应用准备

    实验一Linux系统与应用准备 |这个作业属于哪个课程|内容| | ---- | ---- | ---- | |这个作业属于哪个课程|2021春季Linux系统与应用 (南昌航空大学 - 信息工程学院 ...

  9. hdu:Two Rabbits(区间DP)

    Problem DescriptionLong long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny af ...

  10. PC端钉钉扫码登录,报错情况合集

    "对不起 你无权限查看该页面 redirect_url不能为空" 原因: 1. 只对redirect_url编码,而生成二维码时需要对整个gotoUrl进行编码 2. appid参 ...