jstl 自定义标签

    技术2024-11-19  8

    1.package gp.business.util; public class UtilFunction { public static String find(String name){//方法必须是public static return name; } }

    2.在web-inf下面新建tld文件:

    <?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 http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0"> <tlib-version>1.0</tlib-version> <short-name>my</short-name> <function> <name>find</name> <function-class>gp.business.util.UtilFunction</function-class> <function-signature>java.lang.String find(java.lang.String)</function-signature> </function> </taglib> 

    3.页面调用:

    <%@ taglib prefix="my" uri="/WEB-INF/myfunctions.tld" %>//引入标签库 ${my:find("我爱你")}//使用标签 

     

    最新回复(0)