Jsp default date format
Is it possible to change default f开发者_Go百科ormatting of Date object in JSP pages? Now I have some kind of formatting and I would like to change formatting without using fmt-tags, because that would mean I would have to type that formatting to all pages and there are many!
without using fmt-tags
Best is to create your own custom taglib which does exactly the same as JSTL fmt:formatDate.
But why would you want to reinvent the wheel? Is it the "much" effort of replacing the code in JSP? Well, that's just your job :) It's basically as simple as following:
- Drop jstl-1.2.jar in
/WEB-INF/lib. Declare
fmttaglib in top of your JSP:<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>Use
fmt:formatDateon any bean'sjava.util.Dateproperty.<fmt:formatDate value="${bean.date}" type="date" dateStyle="short" />Above example will print today's date as
10/01/25for English locales and for example25.01.10for German locales. No worries anymore! :)
You would be almost already finished in the time you spent asking the question and waiting the answer ;)
As per my knowledge, it is not possible as JSP will just invoke toString method on the object which you cannot override using settings. You have to do it manually.
加载中,请稍侯......
精彩评论