JSTL 自定义标签

xiaoxiao2021-02-28  8

<?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"     version="2.0">     <description>JSTL 1.1 core library</description>     <display-name>JSTL core</display-name>     <tlib-version>1.1</tlib-version>     <short-name>weijia</short-name>     <uri>http://www.test.cn/mytag</uri>     <tag>         <description>             my first tag         </description>         <name>testTag</name>         <tag-class>com.jstl.TestJSTL</tag-class>         <body-content>jsp</body-content>     </tag>

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

转载请注明原文地址: https://www.6miu.com/read-1400388.html

最新回复(0)