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
|
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>