您的位置:首页 > Web前端 > JavaScript

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

2011-11-10 17:52 786 查看
刚学习了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>


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: