jstl自定义函数

来源:互联网 发布:广电网络维护员 编辑:程序博客网 时间:2024/04/30 04:36

1.自定义函数类

package com.dq.oa.web;


import com.dq.oa.manager.ACLManager;


/**
 * jstl 函数 ,主要功能计时认证
 * */
public class SecurityFunctions {
private static ACLManager aclManager;


public static boolean hasPermission(int userId, String reourceSn,
int permission) {
return aclManager.hasPermissionByResourceSn(userId, reourceSn,
permission);


}


// 不可以是静态的静态的spring注入不进去


public ACLManager getAclManager() {
return aclManager;
}


public void setAclManager(ACLManager aclManager) {
SecurityFunctions.aclManager = aclManager;
}


}

2编写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">
    
  <tlib-version>1.0</tlib-version>
  <short-name>my</short-name>
  <uri>http://www.dq.com/oa/functions</uri>
  
  <function>
    <name>hasPermission</name>
    <function-class>com.dq.oa.web.SecurityFunctions</function-class>
    <function-signature>boolean hasPermission(int, java.lang.String,int)</function-signature>
  </function>
  
</taglib>

3.在jsp文件中调用

<c:if test="${my:hasPermission(login.id,'person',3)}">
<a href="#"
onclick="del('person.do?method=del&id=${person.id }')">删除</a> |
</c:if>