1 5 package org.jresearch.gossip.tags; 6 7 import java.text.DecimalFormat ; 8 import java.util.Date ; 9 10 import javax.servlet.jsp.JspException ; 11 import javax.servlet.jsp.JspWriter ; 12 import javax.servlet.jsp.tagext.TagSupport ; 13 14 import org.jresearch.gossip.IConst; 15 16 21 public class BuildTimeTag extends TagSupport { 22 30 public int doStartTag() throws JspException { 31 try { 32 if (pageContext.getRequest().getAttribute( 33 IConst.REQUEST.START_TIME_KEY) == null) { 34 pageContext.getRequest().setAttribute( 35 IConst.REQUEST.START_TIME_KEY, new Date ()); 36 } 37 } catch (Exception ex) { 38 throw new JspException ("error in BuildTimeTag tag:", ex); 39 } 40 41 return (EVAL_BODY_INCLUDE); 42 } 43 44 52 public int doEndTag() throws JspException { 53 try { 54 JspWriter out = pageContext.getOut(); 55 56 if (pageContext.getRequest().getAttribute( 57 IConst.REQUEST.START_TIME_KEY) != null) { 58 DecimalFormat df = new DecimalFormat (); 59 df.applyPattern("#0.00####"); 60 61 double buildtime = ((new Date ()).getTime() - ((Date ) pageContext 62 .getRequest().getAttribute( 63 IConst.REQUEST.START_TIME_KEY)).getTime()) * 0.001; 64 out.print(df.format(buildtime)); 65 } 66 } catch (Exception ex) { 67 throw new JspException ("error in BuildTimeTag tag:", ex); 68 } 69 70 return (EVAL_PAGE); 71 } 72 } 73 | Popular Tags |