JSTL函数 定义

来源:互联网 发布:ubuntu usr在那里 编辑:程序博客网 时间:2024/05/17 05:59

1 普遍类

2 方法必须是static

3 如果用spring 的话该类的参数的 setxxx();方法需要非static 否则无法注入。

4在WEB-INF 下建立 如 my.tld 文件 在如standard.jar 找到 fn.tld

<?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">
   
  <description>JSTL 1.1 i18n-capable formatting library</description>
  <display-name>JSTL fmt</display-name>
  <tlib-version>1.1</tlib-version>
  <short-name>my</short-name>
  <uri>http://www.bjxt.com/oa/functions</uri>
 
    <function>
    <description>
      Tests if an input string contains the specified substring in a case insensitive way.
    </description>
    <name>containsIgnoreCase</name>
    <function-class>org.apache.taglibs.standard.functions.Functions</function-class>
    <function-signature>boolean containsIgnoreCase(java.lang.String, java.lang.String)</function-signature>
    <example>
      &lt;c:if test="${fn:containsIgnoreCase(name, searchString)}">
    </example>
  </function>
 
</taglib>

 

5 还需要在web.xml 注册下

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

注意 <taglib-uri>需要放在<taglib-location>前面

 <name>containsIgnoreCase</name> 必须和 函数名相同

6 jsp 界面引用

 

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

7使用

<c:if test="${my:hasPermissionBySn(user.id,'user',2)}">
         <a href="#"
          onclick="openWin('user.action?method=updateInput&id=${person.user.id }','chgpsw',600,100);">修改帐号</a>
        </c:if>