开发者

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:

  1. Drop jstl-1.2.jar in /WEB-INF/lib.
  2. Declare fmt taglib in top of your JSP:

    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    
  3. Use fmt:formatDate on any bean's java.util.Date property.

    <fmt:formatDate value="${bean.date}" type="date" dateStyle="short" />
    

    Above example will print today's date as 10/01/25 for English locales and for example 25.01.10 for 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜