1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <%@ taglib prefix="site-utils" uri="http://www.newInstance.com/taglibs/site-utils"%> </td> <td width="16" align="left" valign="top"> </td> </tr> <!-- End main content --> <!-- Begin footer section --> <tr> <td width="91" align="left" valign="top" bgcolor="#330066"> </td> <td align="left" valign="top"> </td> <td class="footer" align="left" valign="top"><div align="center"><br> © 2003 <a href="mailto:webmaster@newInstance.com">Brett McLaughlin</a><br> Last Updated: <site-utils:lastModified format="PHH:mm a, MM/dd/yyyy"/> </div></td> <td align="left" valign="top"> </td> <td width="141" align="right" valign="top" bgcolor="#330066"> </td> </tr> </table> <!-- End footer section --> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | package com.newInstance.site.tags; import java.io.File; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.tagext.TagSupport; public class LastModifiedTag extends TagSupport { private final String DEFAULT_FORMAT = "MMM d, yyyy"; private String format = DEFAULT_FORMAT; public void setFormat(String format) { this.format = format; } // doEndTag() method, as seen in previous tips } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | package com.newInstance.site.tags; import java.io.File; import java.io.IOException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.tagext.TagSupport; public class LastModifiedTag extends TagSupport { private final String DEFAULT_FORMAT = "MMM d, yyyy"; private String format = DEFAULT_FORMAT; public void setFormat(String format) { this.format = format; } public int doEndTag() { try { HttpServletRequest request = (HttpServletRequest)pageContext.getRequest(); String path = pageContext.getServletContext().getRealPath( request.getServletPath()); File file = new File(path); DateFormat formatter; try { formatter = new SimpleDateFormat(format); } catch (IllegalArgumentException e) { formatter = new SimpleDateFormat(DEFAULT_FORMAT); } pageContext.getOut().println( formatter.format(new Date(file.lastModified()))); } catch (IOException ignored) { } return EVAL_PAGE; } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |