कोई अंतर्निहित है विशेषता यह है कि जांच करने के लिए - क्या आप क्या करेंगे अपने स्वयं के टीएलडी समारोह जो एक सूची और एक आइटम लेता है, और कॉल सूची के शामिल() विधि लिखना है। जैसे
//in your own WEB-INF/custom-functions.tld file add this
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<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>
<function>
<name>contains</name>
<function-class>com.Yourclass</function-class>
<function-signature>boolean contains(java.util.List,java.lang.Object)
</function-signature>
</function>
</taglib>
फिर एक वर्ग Yourclass कहा जाता है एक स्थिर विधि से ऊपर हस्ताक्षर के साथ होता है कहा जाता है बनाते हैं, और जोड़ें। मुझे यकीन है कि विधि के क्रियान्वयन सुंदर आत्म व्याख्यात्मक है हूँ:
package com; // just to illustrate how to represent the package in the tld
public class Yourclass {
public static boolean contains(List list, Object o) {
return list.contains(o);
}
}
तो आप इसे अपने jsp में उपयोग कर सकते हैं:
<%@ taglib uri="/WEB-INF/custom-functions.tld" prefix="fn" %>
<c:if test="${ fn:contains(mylist, myValue) }">style='display:none;'</c:if>
टैग साइट में किसी भी JSP से इस्तेमाल किया जा सकता।
संपादित करें: TLD फ़ाइल के बारे में और अधिक जानकारी - more info here
ध्यान दें कि दिए गए वाक्य रचना काम करता है के रूप में ईएल 2.2 के बाद से intented (जो सर्वलेट 3.0 के हिस्से के रूप में लाया जाता है/JSP 2.2 जो दिसंबर 2009 को जारी किया गया था)। – BalusC
[जेएसटीएल सेट्स और सूचियों के संभावित डुप्लिकेट - यदि सेट में आइटम मौजूद है तो जांचें] (http://stackoverflow.com/questions/1076679/jstl-sets-and-lists-checking-if-item-exists-in-a -सेट) –