自定义EL函数

  某些时候我们需要进行比如说 ${"abd" + "scf" }等操作,但是El并不支持,但是EL却有自定义函数的方式来完成操作


配置xml

<?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/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
	version="2.0">

	<tlib-version>1.0</tlib-version>
	<!-- shortname 尽可能和文件名一样。 -->
	<short-name>MyFunction</short-name>
	<!-- uri可以随便写 -->
	<uri>http://tomcat.apache.org/jsp2-example-taglib</uri>


	<!-- 注册函数 -->
	<function>
		<!-- name和方法名一致 -->
		<name>LowerToUpper</name>
		<!-- 拷贝类的全名 -->
		<function-class>com.GYB.com.ELFunctions</function-class>
	<!-- 方法签名 返回值类型 + 方法名 + 参数类型 -->
		<function-signature>java.lang.String LowerToUpper( java.lang.String )</function-signature>
	</function>

</taglib>

要在jsp内添加atglib指令

<%@ taglib prefix="MyFunction" uri="http://tomcat.apache.org/jsp2-example-taglib" %>
	${MyFunction:LowerToUpper("dsafasf") }
	<%
		String username = "tom";
	//El函数只能处理四大域里的数据
		pageContext.setAttribute("usernmae", username);
	%>
	

对于        <body-content>tagdependent</body-content>:

猜你喜欢

转载自blog.csdn.net/s88893325885/article/details/82025685