使用JSTL formatDate标记显示当前日期

问题描述:

我正在使用JSTL在JSP页面中显示当前日期。以下是我正在使用的代码。

I am trying to show the current date in my JSP page using JSTL. below is the code I am using.

<jsp:useBean id="now" class="java.util.Date" scope="request" />
<fmt:formatDate value="${now}" pattern="MM.dd.yyyy" />

但上面的代码没有产生任何结果?我在这里遗漏了什么,还是有更好的方法呢?我正在使用JSTL 1.1。

But the above code is not producing any results? Am I missing anything here or is there any better approach for this? I am using JSTL 1.1.

尝试打印没有格式化,$ {now},你可能有 null 在那里。请求范围内有这个属性吗?只要双重检查,如果是,可能是 null 。如果没有,请尝试从标签中删除此范围属性,是的,这并不重要,只是为了使事情清晰。

Try to print it without formatting, ${now}, you probably have null in there. Do you have this attribute in request scope? Just double check, if yes it might be null. If not, then try remove this scope attribute from the tag, yeah it doesn't matter but just to make the things clear.