| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
openkk
12年前发布

自定义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"    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>

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 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1329182034374.html
JSTL JSP Java开发