在项目应用中,通常需要多个用户公用一个页面,但是每个用户看到的数据或操作不一样,这需要在用户登录时加载该用户的权限,菜单一样,但是显示的页面数据不一样: import java.util.List; import javax.servlet.jsp.JspTagException; import javax.servlet.jsp.tagext.BodyTagSupport; public class BaseRightTag extends BodyTagSupport { String code = null; private String USERFUNCTIONLIST = "userFunctionList"; private static final long serialVersionUID = 4244449146906854876L; public int doStartTag() throws JspTagException { boolean flag = false; if (code == null) { return SKIP_BODY; } //获取用户权限列表 Object obj = pageContext.getSession().getAttribute(USERFUNCTIONLIST); if (obj == null) { flag = false; } else { List functionCodeList = (List) obj; //如果包含这个权限则显示 if(functionCodeList.contains(code)){ flag = true; } } return flag ? EVAL_BODY_INCLUDE : SKIP_BODY; } public int doEndTag() throws JspTagException { return EVAL_PAGE; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } } right-tag.tld配置: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> <taglib> <tlibversion>1.2</tlibversion> <jspversion>1.1</jspversion> <shortname>r</shortname> <tag> <name>if</name> <tagclass>com.emerson.iac.util.BaseRightTag</tagclass> <bodycontent>JSP</bodycontent> <attribute> <name>code</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib> web.xml配置: <jsp-config> <taglib> <taglib-uri>/rightTag</taglib-uri> <taglib-location>/WEB-INF/right-tag.tld</taglib-location> </taglib> </jsp-config> jsp页面应用 <%@ taglib prefix="r" uri="/rightTag" %> <r:if code="该功能的功能码,即用户在这个页面拥有的权限ID"> <!--需求要做的操作--> </r:if>