<?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>1.2</jsp-version> <short-name>ma</short-name> <tag> <name>ma</name> <tag-class>com.sitech.taglib.MenuAuthTag</tag-class> <body-content>JSP</body-content> <attribute> <name>menuName</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>
package com.sitech.taglib; import javax.servlet.http.HttpServletRequest; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.TagSupport; import com.sitech.common.SessionUtil; import com.sitech.privilege.MenuAuthCache; /** * * @author zhangzikui * */ public class MenuAuthTag extends TagSupport { private static final long serialVersionUID = 1L; // 菜单链接名称 private String menuName; @Override public int doStartTag() throws JspException { HttpServletRequest req = (HttpServletRequest) (super.pageContext.getRequest()); String smCode = SessionUtil.getSmCodeByReq(req); // 未登录用户或保密协议用户 if(smCode == null || smCode.matches("//s*")) { smCode = "ki"; } String menu = MenuAuthCache.getMenu(smCode, menuName); // 无权限 if(menu == null) { return SKIP_BODY; } else { return EVAL_BODY_INCLUDE; } } public String getMenuName() { return menuName; } public void setMenuName(String menuName) { this.menuName = menuName; } }
配置使用方法:
web.xml
<jsp-config> <taglib> <taglib-uri>/hkunion/ma</taglib-uri> <taglib-location>/WEB-INF/tlds/menu_authentication.tld</taglib-location> </taglib> </jsp-config>
JSP
<%@ taglib uri="/hkunion/ma" prefix="m"%> <m:ma menuName="sugComplaints"> <td><a href="#">aaaa</a></td> </m:ma>