1. New TLD File:
MY-FUNCTIONS.TLD:
<?XML version= "1.0" encoding= "UTF-8"?><taglibxmlns= "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"> <Description>Functions</Description> <tlib-version>3.0</tlib-version> <Short-name>Fn</Short-name> <URI>Http://mysteel.com/shiro/tags/mysteel-functions</URI> <function> <Description>Show ship name according to ship code</Description> <name>ShipName</name> <Function-class>Com.test.system.web.taglib.Functions</Function-class> <function-signature>Java.lang.String Getshipname (java.lang.String)</function-signature> </function></taglib>
2. Build Java class:
Package Com.test.system.web.taglib; Import Com.portx.util.XmlReaderUtil; Import org.springframework.util.CollectionUtils; Import java.util.Collection; Public class Functions { publicstatic string Getshipname (String code) { return Xmlreaderutil.getvaluebykey (code);} }
3. defined in Web. xml:
<Jsp-config> <taglib> <Taglib-uri>/tags</Taglib-uri> <taglib-location>/web-inf/tld/datetag.tld</taglib-location> </taglib> <taglib> <Taglib-uri>/functions</Taglib-uri> <taglib-location>/web-inf/tld/mysteel-functions.tld</taglib-location> </taglib> </Jsp-config>
4. Call in JSP
<% @ taglib Prefix = " FNC " URI = " /functions " %> ${fnc:shipname (ITEM.SHIPCORPCD)}
can be called.
JSP calls Java method function Taglib