</taglib>
package com.jstl; import java.text.SimpleDateFormat; import java.util.Date; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; /** * 类说明 * * @author 肖荷山 * @version 创建时间:2017年11月11日 上午10:12:31 */ public class TestJSTL extends TagSupport { /** * */ private static final long serialVersionUID = -9073988449891220898L; @Override public int doStartTag() throws JspException { JspWriter out = this.pageContext.getOut(); String sdf = new SimpleDateFormat("yyyy-MM-dd HH : mm : ss").format(new Date()); try { out.print(sdf); } catch (Exception e) { throw new RuntimeException(e); } finally { System.out.println("==================================================================执行这里"); } return super.doStartTag(); } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://www.test.cn/mytag" prefix="mytag"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <h1>=====================loginout</h1> <mytag:testTag /> </body> </html>