} public String getPrivilege() { return privilege; } public void setPrivilege(String privilege) { this.privilege = privilege; } } 3 加两个Tag(Page与Field): SecurityTagForPage.java: package com.**.**.taglib; import java.util.*; public class SecurityTagForPage extends TagSupport { private int permissionID; public int doEndTag() throws JspException { HttpSession session = pageContext.getSession(); //登陆时把该user的userProfile放到session里 UserProfile userProfile = (UserProfile)session.getAttribute("userProfile"); Collection collection= userProfile.getUserPermissions(); Iterator it = collection.iterator() ; while(it.hasNext()) { UserPermission userPermission = (UserPermission)it.next(); if ((permissionID == userPermission.getPermissionId())) { return EVAL_PAGE; } } return SKIP_PAGE; } public int getPermissionID() { return permissionID; } public void setPermissionID(int permissionID) { this.permissionID = permissionID; } } |