自定义JSTL函数

public class SecurityFunction {
//方法需要是static类型的
public static String testJstlFunction(String str) {
System.out.println("执行一些操作"+str);
return "hello jstl";
}
}

 

<?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>
<short-name>my</short-name>
<uri>http://www.dcy.com/functions</uri>
<function>
<name>testJstlFunction</name>
<function-class>com.dcy.test.SecurityFunction</function-class>
<function-signature>java.lang.String testJstlFunction(java.lang.String )</function-signature>
</function>
</taglib>

 

<jsp-config>
<taglib>
<taglib-uri>http://www.dcy.com/functions</taglib-uri>
<taglib-location>/WEB-INF/myFunction.tld</taglib-location>
</taglib>
</jsp-config>

 

 

1、 定义函数类:

 

 

 

2、定义tld文件:myfunction.tld:(一般放到web-inf下)

 

3、修改web.xml文件:

 

 

4、jsp页面引入(注意uri在web.xml和jsp页面引入需要一致,web.xml中的uri可以与location一致,也可以与tld文件中的uri一致,一般三者的uri一致)

<%@ taglib prefix="my" uri="http://www.dcy.com/functions" %>

 

5、 jsp页面使用:

${my:testJstlFunction('teststring')}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值