In Java we can connect strings directly to write String str=str1+str2, in the JSP in the El expression ${1+2} result is 3, and ${' xxx ' + ' xxx '} is wrong, because El has done it, Throws an exception Java.lang.NumberFormatException:For input string: "XXX", but many times we may have such a requirement, so the following is a brief introduction to the custom El expression.
First, you build a Java class Elfuncutil, which has a static method that returns a string of two parameters added.
/**
* Class Description:
*
* @author yjde/public
class Elfuncutil {
/**
* El method to connect two strings * *
@param str1
* @param str2
* @return
/public static string append (String str1, String St R2) {return
str1 + str2;
}
}
Then write a TLD file elfunc.tld.
<?xml version= "1.0" encoding= "UTF-8"?> <taglib xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"
Http://www.w3.org/2001/XMLSchema-instance "
xsi:schemalocation=" Http://java.sun.com/xml/ns/j2ee [url]http:// Java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd[/url] "
version=" 2.0 ">
<tlib-version>1.0 </tlib-version>
<short-name>elf</short-name>
<function>
<description > for connecting two strings </description>
<name>append</name>
<function-class> Com.ourpalm.mis.common.util.ELFuncUtil
</function-class>
<function-signature> Java.lang.String Append (java.lang.string,java.lang.string) </function-signature>
<example>${elf : Append (str1, str2)}</example>
</function>
Finally, we can use our custom El expressions directly in our JSP, and don't forget to import the TLD in the JSP before using it.
<%@ taglib prefix= "elf" uri= "/web-inf/tlds/elfunc.tld"%>
<c:out value= "${elf:append (PARAM.STR1, PARAM.STR2)}"/>