自定義JSTL函數
1、 定義函數類:
public class SecurityFunction {
//方法需要是static類型的
public static String testJstlFunction(String str) {
System.out.println("執行一些操作"+str);
return "hello jstl";
}
}2、定義tld文件:myfunction.tld:(一般放到web-inf下)<?xml version="1.0" encoding="UTF-8"?> <taglib xmlns="http://java.sun.com/xml/ns/j2ee<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></pre>
3、修改web.xml文件:
添加:
<jsp-config> <taglib> <taglib-uri>http://www.dcy.com/functions</taglib-uri> <taglib-location>/WEB-INF/myFunction.tld</taglib-location> </taglib> </jsp-config>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')}轉自:http://blog.csdn.net/sundenskyqq/article/details/7256673
本文由用戶 openkk 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!