1 import javax.servlet.jsp.JspException; 2 import javax.servlet.jsp.tagext.BodyTagSupport; 3 4 /** 5 * Created by Administrator on 2018-4-28. 6 */ 7 public class PrivilegeService extends BodyTagSupport { 8 9 //頁面編碼 10 private String menu; 11 //頁面操做 12 private String sn; 13 14 public PrivilegeService() { 15 } 16 17 public int doStartTag() throws JspException { 18 try { 19 if("check".equals(this.menu)&& "admin".equals(this.sn)) { 20 return 1; 21 } 22 } catch (Exception var3) { 23 } 24 return 0; 25 } 26 27 public int doEndTag() throws JspException { 28 return 6; 29 } 30 31 public String getMenu() { 32 return menu; 33 } 34 35 public void setMenu(String menu) { 36 this.menu = menu; 37 } 38 39 public String getSn() { 40 return sn; 41 } 42 43 public void setSn(String sn) { 44 this.sn = sn; 45 } 46 }
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> 4 5 <taglib> 6 <tlibversion>1.0</tlibversion> 7 <jspversion>2.0</jspversion> 8 <shortname>通用標籤庫</shortname> 9 <info>提供通用組件的標籤庫</info> 10 11 <!-- 細粒度權限檢查標籤 --> 12 <tag> 13 <name>privilege</name> 14 <tagclass>test.service.PrivilegeService</tagclass> 15 <bodycontent>JSP</bodycontent> 16 17 <attribute> 18 <name>menu</name> 19 <required>true</required> 20 <rtexprvalue>true</rtexprvalue> 21 </attribute> 22 23 <attribute> 24 <name>sn</name> 25 <required>true</required> 26 <rtexprvalue>true</rtexprvalue> 27 </attribute> 28 </tag> 29 </taglib>
<%@ taglib prefix='demo' uri='/WEB-INF/tld/privilege.tld' %>
<demo:privilege menu="check" sn="admin"> <button type="button">刪除</button> </demo:privilege>