Structure:
Binaryconverts.java
Package Com.jsp.tag; Public classBinaryconverts { Public Static voidMain (string[] args) {System. out. println (Tobinarystring ("Ten","Ten". Length ())); } /** * 10 binary into 2 * @param s * @param len * @return*/ Public Staticstring tobinarystring (string S,integer len) {Try{Stringstring=integer.tobinarystring (integer.valueof (s)); intL = len-string. Length (); for(intI=0; i<l;i++){ string="0"+string; } return string; } Catch(Exception e) {e.printstacktrace (); } return NULL; }}
Testfunction.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/j2eeweb-jsptaglibrary_2_0.xsd"version="2.0"> <tlib-version>1.0</tlib-version> < Short-name>mytest</ Short-name> <uri>http://zhengcj.test.com</uri><function> <!--el page call name--<name>toBinaryString</name> <!--the processing class for the specified label, specifying The Java class to which the tag is handled. -<function-class>com.jsp.tag.binaryconverts</function-class> <!--Specify the method that is actually called in the name of the El page. Specifies the actual method to handle the class. Parameters and callback functions to write the full path---<function-signature>java.lang.String tobinarystring (Java.lang.string,java.lang.integer)</function-signature> </function> </taglib>
index.jsp
<%@ page language="Java"Contenttype="text/html; Charset=utf-8"pageencoding="UTF-8"%><% @taglib prefix="MYFN"Uri="/web-inf/tld/testfunction.tld"%><! DOCTYPE HTML Public"-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD">"Content-type"Content="text/html; Charset=utf-8"><title>insert title here</title>${myfn:tobinarystring ('Ten',4)}</body>Visit: http://localhost:8090/JspTag/index.jsp
JSP Custom Labels