Java 使用 JSTL formatDate 标签显示当前日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/427726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Showing the current date using JSTL formatDate tag
提问by Veera
I am trying to show the current date in my JSP page using JSTL. below is the code I am using.
我正在尝试使用 JSTL 在我的 JSP 页面中显示当前日期。下面是我正在使用的代码。
<jsp:useBean id="now" class="java.util.Date" scope="request" />
<fmt:formatDate value="${now}" pattern="MM.dd.yyyy" />
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.
但是上面的代码没有产生任何结果?我在这里遗漏了什么还是有更好的方法?我正在使用 JSTL 1.1。
采纳答案by Adeel Ansari
Try to print it without formatting, ${now}, you probably have nullin there. Do you have this attribute in request scope? Just double check, if yes it might be null. If not, then try remove this scopeattribute from the tag, yeah it doesn't matter but just to make the things clear.
尝试在不格式化的情况下打印它,${now},您可能在那里有空值。你在请求范围内有这个属性吗?只需仔细检查,如果是,它可能是null。如果没有,那么尝试从标签中删除这个范围属性,是的,这并不重要,只是为了让事情清楚。
回答by Adeel Ansari
scope=page
works for me
scope=page
为我工作