Java in Java util. Map. Contains() method call
•
Java
Is there any way to call java. in JSP? util. Map. Contains () method, where map is the attribute of the bean
Solution
${fooBean.fooMap.containsValue("baz")}
${fooBean.fooMap.containsValue("baz")}
The above applies to JSP 2.2 or later If you are using a pre JSP 2.2 container (such as Java EE 5), the El function may be a better solution
Static Java methods:
package contains;
import java.util.Map;
public class Maps {
public static boolean containsValue(Map<?,?> map,Object value) {
return map.containsValue(value);
}
}
Document WEB-INF / TLDs / maps tld:
<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.1"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
<tlib-version>1.0</tlib-version>
<short-name>maps</short-name>
<uri>/WEB-INF/tlds/maps</uri>
<function>
<description>Returns true if the value is contained</description>
<name>containsValue</name>
<function-class>contains.Maps</function-class>
<function-signature>
boolean containsValue(java.util.Map,java.lang.Object)
</function-signature>
</function>
</taglib>
Usage:
<%@taglib prefix="maps" uri="/WEB-INF/tlds/maps" %>
...
${maps:containsValue(fooBean.fooMap,"baz")}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
