如何自定义JSTL标签(在oa系统中用JSTL函数解决即时认证问题)

 

刚学习了JSTL函数的创建,现在在这小结一下:

1.建一个类如:

 

package org.yebing.oa.web;

import org.yebing.oa.manager.ACLManager;

public class SecurityFunctions {
 
 private static ACLManager aclManager;
 
 public static boolean hasPermission(int userId,String resourceSn,int permission){
  return aclManager.hasPermissionByResourceSn(userId, resourceSn, permission);
 }

 
 //由于spring不支持static类型的set方法注入
 public  void setAclManager(ACLManager aclManager) {
  SecurityFunctions.aclManager = aclManager;
 }
}

注意:1.方法必须为是static

             2.spring不支持static类型的set方法注入
2.在web-inf下建一my.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/j2eehttp://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.yebing.com/oa/functions</uri>
 
  <function>
    <name>hasPermission</name>
    <function-class>org.yebing.oa.web.SecurityFunctions</function-class>
    <function-signature>boolean hasPermission(int, java.lang.String,int)</function-signature>
  </function>
</taglib>

 

3.再在web.xml中配置此自定义的标签:

 

<jsp-config>
   <taglib>
    <taglib-uri>http://www.yebing.com/oa/myfunctions</taglib-uri>
    <taglib-location>/WEB-INF/my.tld</taglib-location>
   </taglib>
</jsp-config>  

 

4.还需在使用的jsp页面上加上标签声明:

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

5.由于我使用到了spring开发系统,加上在SecurityFunctions用到了aclManager所以要在spring中注入:

<bean id="sucurityFunctions" class="org.yebing.oa.web.SecurityFunctions">
  <property name="aclManager" ref="aclManager"></property>
</bean>

 


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值