permission.tld javascript
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"> <taglib> <tlib-version>1.0</tlib-version> <jsp-version>2.0</jsp-version> <short-name>per</short-name> <!-- backGroundTag --> <uri>http://www.sdyy.tag</uri> <tag> <name>hasUrlPerm</name> <tag-class>com.shenhesoft.logistics.manage.web.utils.tags.HasUrlPermissionTag</tag-class> <attribute> <name>code</name> <required>false</required> <rtexprvalue>true</rtexprvalue> <type>java.lang.String</type> <description>/forMain.do</description> </attribute> </tag> </taglib>
HasUrlPermissionTaghtml
package com.shenhesoft.logistics.manage.web.utils.tags; import java.util.List; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.BodyTagSupport; import com.shenhesoft.logistics.common.session.AppSession; /** * @description * * @author shilvfei * * @date 2018年5月10日 */ public class HasUrlPermissionTag extends BodyTagSupport { private String code;// acApplication/forMain.do @Override public int doStartTag() throws JspException { //獲取session中存放的權限 List<String> permissionCodes = AppSession.getUserPermissionCodes(); //判斷是否有權限訪問 if (permissionCodes.contains(code)) { //容許訪問標籤body return BodyTagSupport.EVAL_BODY_INCLUDE;// 返回此則執行標籤body中內容,SKIP_BODY則不執行 } else { return BodyTagSupport.SKIP_BODY; } } @Override public int doEndTag() throws JspException { return BodyTagSupport.EVAL_BODY_INCLUDE; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }
導入到jsp中java
<%@ taglib uri="/WEB-INF/permission.tld" prefix="per"%>
如何使用web
<per:hasUrlPerm code="driverAccountsFinanceAudit"> <button class="btn-xs btn-primary pull-right checks" id="btnDriverAccountsFinanceAudit">財務審覈</button> </per:hasUrlPerm>
參照文檔:session