一、Java
package test.utils.ctag;
public class CustomTags {
public static boolean equals(String s1,String s2){
if(s1==s2)
return true;
if(s1!=null)
return s1.equals(s2);
return false;
}
}
二、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 web-jsptaglibrary_2_0.xsd"
version="2.0">
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>f</short-name>
<function>
<name>equals</name>
<function-class>test.utils.ctag.CustomTags</function-class>
<function-signature>boolean equals( java.lang.String,
java.lang.String )</function-signature>
</function>
</taglib>
三、web.xml
<jsp-config>
<taglib>
<taglib-uri>/functions</taglib-uri>
<taglib-location>/WEB-INF/classes/functions.tld</taglib-location>
</taglib>
</jsp-config>
四、Jsp
<%@ taglib prefix="f" uri="/functions" %>
${f:equals("Hello","Hello")}<br/>
${f:equals("Hello","World")}<br/>
${f:equals(null,"World")}
本文介绍了一种在Java中使用自定义标签的方法。通过创建一个名为CustomTags的类及equals方法来比较两个字符串是否相等,并在TLD文件中定义了该函数。此外,在web.xml中配置了TLD的位置,并在JSP页面中使用了此自定义标签。
1095

被折叠的 条评论
为什么被折叠?



