java jstl 时间格式,格式化日期并使用JSTL和EL显示日期

How do I format and display a Date object in a JSP, most preferably using JSTL and EL but any other solution is welcome? I can not change the bean object.

I have the following class:

import java.util.Date;

public class Person {

private Date myDate;

public Date getMyDate() {

return myDate;

}

public void setMyDate(Date myDate){

this.myDate = myDate;

}

}

I am trying to display the date in this object in a JSP page. When I do this

and it gave me the following error

Unable to convert string '${myDate}' to class java.util.Date for attribute value: java.lang.IllegalArgumentException: Property Editor not registered with the PropertyEditorManager

Then I tried the following:

and I got:

Unparseable date: "${myDate }"

解决方案

Your code should normally work. Try like this:

type="date" pattern="MM-dd-yyyy" />

${formattedDate}

It usually doesn't work if you have wrong JSTL declarations to match your Servlet/JSP version. Make sure you read this before trying anything else: How to Reference and Use JSTL in your Web Application.

If you don't know exactly your environment, you can perform some tests to find out the versions although a simple ${1 + 2} written in your JSP should be a good indicator of the JSP version. If you see 3 in your browser then you are using JSP 2.x, if you see the string ${1 + 2} instead then you are on JSP 1.x.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值