用一个字段封装权限 like : a,b,c,d,e,f,g然后在每一页都要判断一下有没有权限

解决方案 »

  1.   

    可以写一个TAG,然后把那个tag加到每张需要验证的页面,在那个tag的实现class中实现doEndTag()方法,然后拿session中的权限和我们加到每张页面上的权限来比较,不相同则调用pageContext.forward();方法重定向到其他页面,相同则什么都不做。
      

  2.   

    用户接口可以用一个视图来实现
    create or replace view v_menu as
    select distinct u.userid,u.username,r_p.priv,menu.menuname,menu.menuurl,menu.menulevel,menu.fatherid,menu.menuorder,menu.menuid
        from 
        sysuser u,
        role r,
        userrole u_r,
        rolepriv r_p,
        menu
        where
        u.userid=u_r.userid
        and 
        r.roleid=u_r.roleid
        and 
        r.roleid=r_p.roleid
        and 
        r_p.menuid=menu.menuid
        and 
        r_p.priv='2'--具有操作权限
      

  3.   

    谢谢各位! 
    我现在采用的方式和上面 smartzhang(每天多学一点)  说的基本一样! 现在就是还不知道在页面中如何控制!  
    jamesgf(james)  你所说的写tag 来控制,能不能给我个例子! 谢谢你!  这个我感觉好象比较好,就是我现在还不会 ! :(另外,我听人说,如何用目录来实现,不知道有没有人研究过这个东西,希望能交流~ 
      

  4.   

    //tag class
    package com.ncs.roms;import javax.servlet.jsp.tagext.*;
    import javax.servlet.jsp.*;
    import java.text.*;
    import java.util.Date;
    import javax.servlet.*;
    import com.ncs.roms.admin.common.UserValueObject;public class AccessControlTag  extends BodyTagSupport{

    private String role=null;
    public String getRole()
    {
    return role;
    }

    public void setRole(String value)
    {
    this.role = value.toUpperCase();
    } public int doAfterBody() throws JspException
    {
    try
    {
    BodyContent bc = getBodyContent();
      String body = bc.getString();
    JspWriter out = bc.getEnclosingWriter();
    UserValueObject vo = (UserValueObject)pageContext.getSession().getAttribute("validUser");
    String userRole = "U";
    if (vo != null)
    userRole = vo.getRole().toUpperCase();
    int valid = role.indexOf(userRole);
    if(valid == -1)
    {
    pageContext.forward("/jsp/admin/accesscontrol/1.jsp");
    } else if (valid >= 0)
    {
    out.print(body);
    }
    }catch(Exception e){
    throw new JspException(e.toString());
    }
    return SKIP_BODY;
    }
    }然后在每张页面上加上
    <%@ taglib prefix="acltag" uri="/WEB-INF/tlds/exampleTag.tld" %>
    <acltag:acl role="m/a/c">
    ..........
    </acltag:acl>