Sign In/My Account | View Cart  

advertisement

AddThis Social Bookmark Button

Article:
  Getting the Most Out of the Struts Tag Libraries
Subject:   how to use format with dates
Date:   2003-12-04 23:19:02
From:   anonymous2
Response to: how to use format with dates

First, I tried to some dates "the struts-way" self referencing the session in the session by putting
session.setAttribute("thisSess", session);


This would great because I can always see what my session is doing.
The drawback that the time was formatted in milliseconds since 1970. So, I tried to use the struts "format" attribute, but the below 'format="HH:mm:ss"' unfortunately was useless


<<Logged in since <bean:write name="thisSess"
property="creationTime" filter="true" format="HH:mm:ss" />, last access: <bean:write
name="thisSess" property="lastAccessedTime"
filter="true" format="HH:mm:ss" />, max inactive interval: <bean:write name="thisSess"
property="maxInactiveInterval" filter="true" format="HH:mm:ss" />


so, I ended up doint it as
<<
<%
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("HH:mm:ss");
String lastAccessTime = df.format(new java.sql.Date(session.getLastAccessedTime()));
String sessCreateTime = df.format(new java.sql.Date(session.getCreationTime()));
String maxInactiveInterval = Integer.toString(session.getMaxInactiveInterval());


pageContext.setAttribute("lastAccessTime", lastAccessTime);
pageContext.setAttribute("sessCreateTime", sessCreateTime);
pageContext.setAttribute("maxInactiveInterval", maxInactiveInterval);
%><bean:write name="lastAccessTime" filter="true" />, lastAccess: <bean:write name="lastAccessTime"
filter="true" />, maxInactive: <bean:write name="maxInactiveInterval"
filter="true" />sec
>>


if anybody knows how to do it purely in struts, please let me know at hauser@acm.org

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • how to use format with dates
    2004-03-09 15:28:55  jonathan@fallinhouse.com [View]

    You can use Jakarta DateTime TagLib. Information located here. http://jakarta.apache.org/taglibs/doc/datetime-doc/datetime-1.0/index.html

    With the Date Time Taglib, you can implement what you want like this:

    Logged in Since: <dt:format pattern="HH:mm:ss" locale="true"><bean:write name="thisSess" property="creationTime"></dt:format>,
    Last access: <dt:format pattern="HH:mm:ss" locale="true"><bean:write name="thisSess" property="lastAccessedTime" /></dt:format>,
    Max inactive interval: <dt:format pattern="HH:mm:ss" locale="true"><bean:write name="thisSess" property="maxInactiveInterval" /></dt:format>
    • how to use format with dates
      2008-03-12 17:54:30  rafaelpl [View]

      Hi I try to use Jakarta DateTime TagLib in one type java.util.Date both when ty execute prin en the page web the text "Invalid Date"

      exist someone posibility of to use Jakarta DateTime TagLib in java.util.Date ?

      my mail is el.muu.1@gmail.com