If the Jstl method library does not meet your needs, you can use a custom method to extend
public class function{public static int Length (object obj) { //returns the length of the object if (obj = = null) { return 0; } if (obj instanceof stringbuffer) { return Lenth (((stringbuffer) obj). toString ()); } if (obj instanceof String) { return ((String) obj). getbytes.length; } if (obj instanceof Collection) { return ((Collection) obj). Size ();}} }
Configuration file
<?xml version= "1.0" ecoding= "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-jsptaglibr Ary_2_0.xsd version= "2.0" > <description>custom functionslibrary</description> <display-n Ame>customfunctions</display-name> <tlibversion>1.1</tlibversion> <shortname>function </shortname> <uri>http://www.clf.com/tags</uri> <function> <description >descriptioncontent </description> <name>lenth</name> <function-class>c om.chen.funtion</function-class> <function-signature> int Length (java.lang.Obje CT) </function-signature> <example> ${fn:length (String)} </example> <fuNction> </taglib>
The declaration of the custom method is written in the <function-signature> tag, in the form
The return value method name (parameter 1 type, parameter 2 type ...) )
Add a string variable, assign "string test"
The tag library defined in the JSP page is prefixed with "FN", then use the following
${fn:length (String)}
This sentence will be able to output the length of the string
JSP Custom Method Library