javaweb+SSH實現簡單的權限管理系統


權限管理,平時里很多地方我們都可以看到,比如聊QQ時群里的群主、管理員以及成員之間的功能是不一樣的……大家一定會遇到的一個問題,所以整理 一下自己寫權限系統的一些經驗給大家,只起參考作用,也望大家笑納。哈哈哈

一、為什么要實現權限系統

1、 系統中的權限系統,缺少組織結構管理。例如:樹型的組織結構,有些系統雖然考慮了分層,但是沒有考慮分多少層,
組織結構是否考慮了集團公司,全國連鎖經營這種模式,實際上就是很多個獨立單位的概念。很多系統遇到這個問題,
就需要重新做整個系統。
2、 不同登陸用戶要有不同的權利,而且要有不同的菜單,如果不能靈活的修改他們的權限,那用戶需求一旦變化,不是就
很郁悶了。系統要能夠解決這個問題,我們就要靈活的控制每個頁面。即便是系統已經開發完成,投入運行,也可以
通過修改配置文件,而實現權限的重新調整。

二、權限簡單控制原理:

規則一:每個登陸的用戶,可以有多個角色,
規則二:每個角色又可以訪問多個功能點,
規則三:每個功能點又由多個頁面組成。
根據這個對應關系,就可以讓每個用戶對應到不同的頁面,如果進行細致設置,基本上可以解決了應用中的很多情況。

三、名詞解釋:

頁面(URL):在web開發中也稱為URL,最朴素的權限控制,就是基於頁面的控制,即賦予訪問者可以訪問頁面的范圍,
在系統記錄所有的頁面,配置權限時,將允許訪問的頁面,賦予使用者.雖然簡單,卻很直接和容易理解.基於這個思
想,將軟件的URL作為權限,進行控制.將所有的URL進行記錄.但如果直接將URL作為權限,配置給使用者,
是相當麻煩的.因為,一個操作功能,往往不是在一個請求內完成的,這就意味着為了讓使用者有權利完成一個功能,
就必須將一組URL賦予使用者,以便其訪問,顯然這樣給系統管理和維護帶來了很多不方便.因此我們就需要功能點.

功能點: 是一組不可分割URL,因為這組URL共同完成一個功能,因此他們是不可分開的.使用者要正常完成操作,就必須有權
訪問這組URL中的每一個.這樣,將一個功能點賦予使用者,也就意味着這個使用者有訪問這些URL的能力.在業務中,
系統管理員不用關心到底什么權限對應哪些URL,只要將功能點賦予使用者,就可以關聯URL了,完成授權過程.

角色: 角色又可以成為"崗位",它是一組功能點.很多時候,多個使用者的操作權限是相同的,例如一個部門中,大家都有察看自
己郵箱的權利,都有修改自己口令和基本信息的權利,這時,就將郵箱功能點,修改口令,基本信息維護這幾個功能點集合起
來,建立一個角色--"操作員崗",那么,在給使用者授權時,只要將這個角色賦予使用者,該使用者就擁有了相應的功能操
作權限.適合多使用者權限的管理,尤其是使用者數量眾多,而且權限相同或者類似時,可以減少很多麻煩,減少出錯概率.
同時,一個使用者可以同時擁有多個角色,這些角色所代表的權限,使用者可以同時擁有,是權限的並集.
例如一個部門經理可以有"操作員"角色,具備基本的操作權限,同時還可以將"部門審核員"這個角色授予他,這樣可以作操
作部分管理功能.這樣做,可以靈活的組合和配置使用者權限,適應復雜權限管理.

用戶:是軟件系統使用者的系統賬號.每個使用者,都有自己獨一無二的賬號,系統通過這個賬號來識別不同的使用者.賬號的安全
是通過使用者口令加以保護的.口令在系統中是用加密的方式進行保存,避免了通過數據庫系統泄漏使用者口令的問題.系統
使用者是通過"用戶"與"功能點"關聯,完成使用者的授權,在使用者登陸系統后,也是通過"用戶"來認證當前使用者的權限.

四、數據庫設計:

一個用戶可以擁有多個權限,同時一個權限也可以賦予多個用戶,那么用戶和權限就是多對多的關系,那么久需要角色
表來維護和鏈接用戶和權限的關系。通過用戶和角色關聯,角色和權限關聯,從而實現用戶和權限的一個間接關系。那么
問題又來了,用戶和角色也是多對多的關系,角色和權限也是多對多的關系,我們還需要兩張中間表,就是
用戶角色表和角色權限表。
1、用戶表:登錄的用戶
2、角色表:與權限相關聯
3、權限(功能)表:與角色相關聯
4、用戶角色表:用戶和角色的中間表
5、角色功能表:角色和功能的中間表

五、簡單程序設計:

1、導入相關的包

以及SPRING的相關包
1、用戶,角色,權限(功能),角色權限,用戶角色五個實體類對應五張表(省略...)
2、action層調用service層,service層調用dao層
action是界面層:管理業務(service)調度和管理跳轉的,是一個管理器,只負責管理
service是業務邏輯層:管理具體功能和邏輯的,負責實施
DAO數據訪問層:只完成增刪改查,只負責封裝,具體的如何去實現由service實施
3、action:實現頁面的功能
service:先定義一個接口抽象出具有的功能,再由impl去具體的實現。dao也是如此

六、源碼

在寫權限管理的時候最頭痛的地方也就是權限功能的模塊了,但是不管是怎樣的一個業務也是數據的增刪改查操作

以下是功模塊的源碼

 

 

1、功能塊的實體類對象

package com.myauth.functions.entity;

import java.util.*;

import javax.persistence.*;

import com.myauth.module.entity.Module;
import com.myauth.relationship.entity.RoleFunction;

//把這個類實體化,並設置其對應表
@Entity
@Table(name = "functions")
public class Function implements java.io.Serializable {
    // 對應數據表字段的變量
    private Integer id;
    private Module module;
    private String url;
    private String functionname;
    // 對應一對多關聯變量
    private Set<RoleFunction> roleFunctions = new HashSet<RoleFunction>(0);

    // 空構造方法
    public Function() {
    }

    // 設置關聯屬性
    @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
    @JoinColumn(name = "moduleid")
    public Module getModule() {
        return module;
    }

    public void setModule(Module module) {
        this.module = module;
    }

    // 設置表中對應字段
    @Column(name = "functionname")
    public String getFunctionname() {
        return functionname;
    }

    public void setFunctionname(String functionname) {
        this.functionname = functionname;
    }

    // 設置變量id對應數據庫表字段為id,且為主鍵,並設置其主鍵策略為SEQUENCE
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id")
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    // 設置表中對應字段
    @Column(name = "url")
    public String getUrl() {
        return this.url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    // 設置關聯屬性
    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "function")
    public Set<RoleFunction> getRoleFunctions() {
        return this.roleFunctions;
    }

    public void setRoleFunctions(Set<RoleFunction> roleFunctions) {
        this.roleFunctions = roleFunctions;
    }

}


2、定義一個功能DAO接口並實現,以下是實現代碼

package com.myauth.functions.dao;

import java.util.List;

import javax.persistence.*;

import com.myauth.functions.entity.Function;
import com.myauth.persistence.EntityManagerHelper;

public class FunctionDAO implements IFunctionDAO {
    // 聲明靜態常量
    public static final String URL = "url";
    public static final String FUNCTIONNAME = "functionname";

    // 得到實體管理器
    private EntityManager getEntityManager() {
        return EntityManagerHelper.getEntityManager();
    }

    // 新增數據
    public void save(Function entity) {
        EntityManagerHelper.beginTransaction();
        try {
            getEntityManager().persist(entity);
            EntityManagerHelper.commit();
        } catch (RuntimeException re) {
            EntityManagerHelper.rollback();
            throw re;
        }
    }

    // 刪除數據
    public void delete(Function entity) {
        EntityManagerHelper.beginTransaction();
        try {
            entity = getEntityManager().getReference(Function.class,
                    entity.getId());
            getEntityManager().remove(entity);
            EntityManagerHelper.commit();
        } catch (RuntimeException re) {
            EntityManagerHelper.rollback();
            throw re;
        }
    }

    // 修改數據
    public Function update(Function entity) {
        EntityManagerHelper.beginTransaction();
        try {
            Function result = getEntityManager().merge(entity);
            EntityManagerHelper.commit();
            return result;
        } catch (RuntimeException re) {
            EntityManagerHelper.rollback();
            throw re;
        }
    }

    // 通過id查詢數據
    public Function findById(Integer id) {
        try {
            Function instance = getEntityManager().find(Function.class,
                    id);
            return instance;
        } catch (RuntimeException re) {
            throw re;
        }
    }

    // 通過表中一個字段查詢數據
    @SuppressWarnings("unchecked")
    public List<Function> findByProperty(String propertyName,
            final Object value) {
        try {
            final String queryString = "select model from Function model where model."
                    + propertyName + "= :propertyValue";
            Query query = getEntityManager().createQuery(queryString).setHint(
                    "toplink.refresh", true);
            query.setParameter("propertyValue", value);
            return query.getResultList();
        } catch (RuntimeException re) {
            throw re;
        }
    }

    // 查詢所有數據
    @SuppressWarnings("unchecked")
    public List<Function> findAll() {
        try {
            final String queryString = "select model from Function model";
            Query query = getEntityManager().createQuery(queryString).setHint(
                    "toplink.refresh", true);
            return query.getResultList();
        } catch (RuntimeException re) {
            throw re;
        }
    }

    
}


3、定義一個service接口實現具體的增刪改查操作,並實現,以下是實現代碼

package com.myauth.functions.service;

import java.util.ArrayList;
import java.util.List;

import com.myauth.functions.dao.IFunctionDAO;
import com.myauth.functions.entity.Function;
import com.myauth.module.dao.IModuleDAO;
import com.myauth.module.entity.Module;
import com.myauth.relationship.dao.IRoleFunctionDAO;
import com.myauth.relationship.entity.RoleFunction;

public class FunctionFacade implements IFunctionFacade {
    private IRoleFunctionDAO rfd;
    private IFunctionDAO fd;
    private IModuleDAO md;

    // getter和setter方法省略
    public IRoleFunctionDAO getRfd() {
        return rfd;
    }

    public void setRfd(IRoleFunctionDAO rfd) {
        this.rfd = rfd;
    }

    public IFunctionDAO getFd() {
        return fd;
    }

    public void setFd(IFunctionDAO fd) {
        this.fd = fd;
    }

    public IModuleDAO getMd() {
        return md;
    }

    public void setMd(IModuleDAO md) {
        this.md = md;
    }

    // 瀏覽可執行功能
    public List<Function> findFunction(List<Integer> rid, Module m) {
        List<Function> listfunction = new ArrayList<Function>();
        for (Integer i : rid) {
            listfunction.addAll(rfd.findFInRM(i, m));
        }
        return listfunction;
    }

    // 瀏覽全部功能
    public List<Function> findFByMId(Module m) {
        return fd.findByProperty("module.id", m.getId());
    }

    // 單查功能
    public Function findSingleFunction(Function f) {
        return fd.findById(f.getId());
    }

    // 修改功能
    public void modifyFunction(Function f) {
        fd.update(f);
    }

    // 新增功能
    public void newFunction(Function f, Integer mid) {
        Module pf = new Module();
        pf = md.findById(mid);
        // 設置當前功能所屬模塊id
        f.setModule(pf);
        fd.save(f);
    }

    // 刪除功能
    public void removeFunction(Function f) {
        // 刪除功能時將其在關聯表中的所有數據刪除
        for (RoleFunction roleFunction : rfd.findByProperty("function.id",
                f.getId())) {
            rfd.delete(roleFunction);
        }
        fd.delete(f);
    }
}


4、定義action方法實現與頁面之間的交互工作

package com.myauth.functions.action;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.myauth.functions.entity.Function;
import com.myauth.functions.service.IFunctionFacade;
import com.myauth.module.entity.Module;
import com.opensymphony.xwork2.Action;

public class FunctionAction {
    // 針對於頁面的成員變量
    private Function f;
    private Module m;
    private IFunctionFacade ff;
    private List<Function> lf;

    // 構造方法,用於對成員變量賦初值
    public FunctionAction() {
        f = new Function();
        m = new Module();
    }

    // getter和setter方法
    public Function getF() {
        return f;
    }

    public void setF(Function f) {
        this.f = f;
    }

    public Module getM() {
        return m;
    }

    public void setM(Module m) {
        this.m = m;
    }

    public IFunctionFacade getFf() {
        return ff;
    }

    public void setFf(IFunctionFacade ff) {
        this.ff = ff;
    }

    public List<Function> getLf() {
        return lf;
    }

    public void setLf(List<Function> lf) {
        this.lf = lf;
    }

    // 處理newFunction請求的方法
    public String newFunction() {
        // 將模塊id從session中取出
        HttpSession hs = ServletActionContext.getRequest().getSession();
        ff.newFunction(f, (Integer) hs.getAttribute("mid"));
        return Action.SUCCESS;
    }

    // 處理findFunction請求的方法
    @SuppressWarnings("unchecked")
    public String findFunction() {
        // 將角色信息從session中取出
        HttpSession hs = ServletActionContext.getRequest().getSession();
        lf = ff.findFunction((List<Integer>) hs.getAttribute("role"),m);
        return Action.SUCCESS;
    }

    // 處理removeFunction請求的方法
    public String removeFunction() {
        ff.removeFunction(f);
        return Action.SUCCESS;
    }

    // 處理findSingleFunction請求的方法
    public String findSingleFunction() {
        f = ff.findSingleFunction(f);
        return Action.SUCCESS;
    }

    // 處理modifyFunction請求的方法
    public String modifyFunction() {
        ff.modifyFunction(f);
        return Action.SUCCESS;
    }

    // 處理findFByMId請求的方法
    public String findFByMId() {
        HttpSession hs = ServletActionContext.getRequest().getSession();
        // 判斷m是否為空
        if (m == null || m.getId() == null) {
            // 如果m為空將session中的mid值賦給m的id值
            m.setId((Integer) hs.getAttribute("mid"));

        } else {
            // 將模塊id做成session
            hs.setAttribute("mid", m.getId());
        }
        lf = ff.findFByMId(m);
        ServletActionContext.getRequest().setAttribute("FNo", lf.size());
        return Action.SUCCESS;
    }
}


5、權限管理是一個菜單樹的形式,下面是實現菜單樹的頁面代碼

<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
    <title>功能樹</title>
</head>
    <body>
        <s:fielderror></s:fielderror>
        <table>
            <s:iterator value="lf">
                <tr>
                    <td>
                        <a href=<s:url action="%{url}"/> target="content">
                            <h3><s:property value="functionname"/></h3>
                        </a>
                    </td>
                </tr>
            </s:iterator>
        </table>
        <a href="exit.action" target="content"><h4>退出登錄</h4></a>
    </body>
</html>


6、添加新的功能

<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
    <head>
        <title>新增功能頁</title>
    </head>
    <body>
        <form action="newFunction.action" method="post">
            <table width="700" height="400" border="0" align="center">
                <tr>
                    <td valign="top">
                        <table height=28 cellSpacing=0 cellPadding=0 width="90%"
                            align=center
                            background="<%=request.getContextPath()%>/image/border/border1/topcenter.gif"
                            border=0>
                            <tbody>
                                <tr id=cat>
                                    <td vAlign=top align=left width=28 height=28>
                                        <IMG height=28
                                            src="<%=request.getContextPath()%>/image/border/border1/topleft.gif"
                                            width=28 border=0>
                                    </td>

                                    <td width="189" height=28 align=left vAlign=center
                                        background="<%=request.getContextPath()%>/image/border/border1/topbg.gif">
                                        &nbsp;
                                    </td>

                                    <td vAlign=center align=left width=28>
                                        <IMG height=28
                                            src="<%=request.getContextPath()%>/image/border/border1/topend.gif"
                                            width=19 border=0>
                                    </td>

                                    <td vAlign=top align=right width="157"></td>

                                    <td vAlign=top align=right width=296 height=28>
                                        <IMG height=28
                                            src="<%=request.getContextPath()%>/image/border/border1/topright.gif"
                                            width=296 border=0>
                                    </td>

                                </tr>
                            </tbody>
                        </table>
                        <table cellSpacing=0 cellPadding=0 width="90%" align=center
                            bgColor=#89959b border=0>
                            <tbody>
                                <tr>
                                    <td>
                                        <table cellSpacing=1 cellPadding=4 width="100%" border=0>
                                            <tbody>
                                                <tr vAlign="bottom" align="middle">
                                                    <td
                                                        background="<%=request.getContextPath()%>
                                                        /image/border/border1/greenbarbg.gif"
                                                        width="20%" height="30" colspan="2">
                                                    </td>
                                                </tr>
                                                <tr align="center">
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <FONT face="verdana, arial, helvetica,宋體"> 功能名 
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <s:textfield name="f.functionname" theme="simple" />
                                                    </td>
                                                </tr>
                                                <tr align="center">
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <FONT face="verdana, arial, helvetica,宋體"> 功能路徑 
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <s:textfield name="f.url" theme="simple" />
                                                    </td>
                                                </tr>
                                                <tr vAlign="bottom" align="right">
                                                    <td
                                                        background="<%=request.getContextPath()%>
                                                        /image/border/border1/greenbarbg.gif"
                                                        width="20%" height="30" colspan="2">
                                                        <s:submit value="新增" theme="simple" />
                                                        <s:reset value="重置" theme="simple" />
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                        </table>
                        <table width="90%" height=23 border=0 align="center" cellPadding=0
                            cellSpacing=0>
                            <tbody>
                                <tr>
                                    <td vAlign=top align=left width=100 height=23>
                                        <IMG height=23
                                            src="<%=request.getContextPath()%>/image/border/border1/bottomleft.gif"
                                            width=100>
                                    </td>
                                    <td width="100%"
                                        background="<%=request.getContextPath()%>/image/border/border1/bottomcenter.gif"
                                        height=23>
                                        <IMG height=1
                                            src="<%=request.getContextPath()%>/image/border/border1/clear.gif"
                                            width="100%">
                                    </td>
                                    <td vAlign=top align=right width=100 height=23>
                                        <IMG height=23
                                            src="<%=request.getContextPath()%>/image/border/border1/bottomright.gif"
                                            width=100 border=0>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>


7、修改功能頁面

<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
    <title>修改功能頁</title>
</head>
    <body>
        <form action="modifyFunction.action" method="post">
        <table width="700" height="400" border="0" align="center">
                <tr>
                    <td valign="top">
                        <table height=28 width="90%" align=center background="<%=request.getContextPath()%>/image/border/border1/topcenter.gif" border=0>
                            <tbody>
                                <tr id=cat>
                                    <tr vAlign=top align=left width=28 height=28>
                                        <img height=28 src="<%=request.getContextPath()%>/image/border/border1/topleft.gif" width=28 border=0>
                                    </td>

                                    <td width="189" height=28 align=left vAlign=center
                                        background="<%=request.getContextPath()%>/image/border/border1/topbg.gif">
                                        &nbsp;
                                    </td>

                                    <td vAlign=center align=left width=28>
                                        <img height=28
                                            src="<%=request.getContextPath()%>/image/border/border1/topend.gif"
                                            width=19 border=0>
                                    </td>

                                    <td vAlign=top align=right width="157"></td>

                                    <td vAlign=top align=right width=296 height=28>
                                        <img height=28
                                            src="<%=request.getContextPath()%>/image/border/border1/topright.gif"
                                            width=296 border=0>
                                    </td>

                                </tr>
                            </tbody>
                        </table>
                        <table cellSpacing=0 cellPadding=0 width="90%" align=center bgColor=#89959b border=0>
                            <tbody>
                                <tr>
                                    <td>
                                        <table cellSpacing=1 cellPadding=4 width="100%" border=0>
                                            <tbody>
                                                <tr vAlign="bottom" align="middle">
                                                    <td
                                                        background="<%=request.getContextPath()%>
                                                        /image/border/border1/greenbarbg.gif"
                                                        width="20%" height="30" colspan="2">
                                                    </td>
                                                </tr>
                                                <tr align="center">
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <FONT face="verdana, arial, helvetica,宋體"> 功能序號 
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <s:textfield name="f.id" value="%{f.id}" theme="simple" readonly="true"/>
                                                    </td>
                                                </tr>
                                                <tr align="center">
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <FONT face="verdana, arial, helvetica,宋體"> 所屬模塊id 
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <s:textfield name="f.module.id" value="%{f.module.id}" readonly="true" theme="simple"/>
                                                    </td>
                                                </tr>
                                                <tr align="center">
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <FONT face="verdana, arial, helvetica,宋體"> 功能名
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <s:textfield name="f.functionname" value="%{f.functionname}" theme="simple"/>
                                                    </td>
                                                </tr>
                                                <tr align="center">
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <FONT face="verdana, arial, helvetica,宋體"> 功能路徑 
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <s:textfield name="f.url" value="%{f.url}" theme="simple"/>
                                                    </td>
                                                </tr>
                                                <tr vAlign="bottom" align="right">
                                                    <td
                                                        background="<%=request.getContextPath()%>
                                                        /image/border/border1/greenbarbg.gif"
                                                        width="20%" height="30" colspan="2">
                                                        <s:submit value="修改" theme="simple" />
                                                        <s:reset value="重置" theme="simple" />
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                        </table>
                        <table width="90%" height=23 border=0 align="center" cellPadding=0
                            cellSpacing=0>
                            <tbody>
                                <tr>
                                    <td vAlign=top align=left width=100 height=23>
                                        <IMG height=23
                                            src="<%=request.getContextPath()%>/image/border/border1/bottomleft.gif"
                                            width=100>
                                    </td>
                                    <td width="100%"
                                        background="<%=request.getContextPath()%>/image/border/border1/bottomcenter.gif"
                                        height=23>
                                        <IMG height=1
                                            src="<%=request.getContextPath()%>/image/border/border1/clear.gif"
                                            width="100%">
                                    </td>
                                    <td vAlign=top align=right width=100 height=23>
                                        <IMG height=23
                                            src="<%=request.getContextPath()%>/image/border/border1/bottomright.gif"
                                            width=100 border=0>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>


8、操作功能頁

<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
    <head>
        <title>操作功能頁</title>
    </head>
    <body>
        <table width="700" height="400" border="0" align="center">
            <tr>
                <td valign="top">
                    <table height=28 width="90%" align=center
                        background="<%=request.getContextPath()%>/image/border/border1/topcenter.gif"
                        border=0>
                        <tbody>
                            <tr id=cat>
                                <td vAlign=top align=left width=28 height=28>
                                    <IMG height=28
                                        src="<%=request.getContextPath()%>/image/border/border1/topleft.gif"
                                        width=28 border=0>
                                </td>

                                <td width="189" height="28" align="left" vAlign="center"
                                    background="<%=request.getContextPath()%>/image/border/border1/topbg.gif">
                                    &nbsp;
                                </td>

                                <td vAlign=center align=left width=28>
                                    <IMG height=28
                                        src="<%=request.getContextPath()%>/image/border/border1/topend.gif"
                                        width=19 border=0>
                                </td>

                                <td vAlign=top align=right width="157"></td>

                                <td vAlign=top align=right width=296 height=28>
                                    <IMG height=28
                                        src="<%=request.getContextPath()%>/image/border/border1/topright.gif"
                                        width=296 border=0>
                                </td>

                            </tr>
                        </tbody>
                    </table>
                    <table cellSpacing=0 cellPadding=0 width="90%" align=center bgColor=#89959b border=0>
                        <tbody>
                            <tr>
                                <td>
                                    <table cellSpacing=1 cellPadding=4 width="100%" border=0>
                                        <tbody>
                                            <tr vAlign="bottom" align="center">
                                                <td
                                                    background="<%=request.getContextPath()%>
                                                    /image/border/border1/greenbarbg.gif"
                                                    width="20%">
                                                    <div align="center">
                                                        <FONT face="verdana, arial, helvetica,宋體" color=#ffffff><B>功能序號</B>
                                                        </FONT>
                                                    </div>
                                                </td>

                                                <td
                                                    background="<%=request.getContextPath()%>
                                                    /image/border/border1/greenbarbg.gif"
                                                    width="20%">
                                                    <div align="center">
                                                        <FONT face="verdana, arial, helvetica,宋體" color=#ffffff><B>所屬模塊id</B>
                                                        </FONT>
                                                    </div>
                                                </td>

                                                <td
                                                    background="<%=request.getContextPath()%>
                                                    /image/border/border1/greenbarbg.gif"
                                                    width="20%">
                                                    <div align="center">
                                                        <FONT face="verdana, arial, helvetica,宋體" color=#ffffff><B>url</B>
                                                        </FONT>
                                                    </div>
                                                </td>
                                                <td
                                                    background="<%=request.getContextPath()%>
                                                    /image/border/border1/greenbarbg.gif"
                                                    width="20%">
                                                    <div align="center">
                                                        <FONT face="verdana, arial, helvetica,宋體" color=#ffffff><B>功能名</B>
                                                        </FONT>
                                                    </div>
                                                </td>
                                                <td
                                                    background="<%=request.getContextPath()%>
                                                    /image/border/border1/greenbarbg.gif"
                                                    width="20%">
                                                    <div align="center">
                                                        <FONT face="verdana, arial, helvetica,宋體" color=#ffffff><B>刪除操作</B>
                                                        </FONT>
                                                    </div>
                                                </td>
                                            </tr>
                                            <s:iterator value="lf">
                                                <tr align=center>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <FONT face="verdana, arial, helvetica,宋體"><s:property
                                                                value="id" />
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <s:property value="module.id" />
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <s:property value="url" />
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <a
                                                            href='<s:url action="findSingleFunction"><s:param name="f.id" value="id" /></s:url>'
                                                            target="content"> <s:property value="functionname" />
                                                        </a>
                                                    </td>
                                                    <td onmouseover="this.bgColor='#ffffff'"
                                                        onmouseout="this.bgColor='#f5f5f5'" align=left
                                                        bgColor=#f5f5f5>
                                                        <a
                                                            href='<s:url action="removeFunction"><s:param name="f.id" value="id" /></s:url>'
                                                            target="content"> 刪除 </a>
                                                    </td>
                                                </tr>
                                            </s:iterator>

                                            <tr id=cat>
                                                <td align="center"
                                                    background="<%=request.getContextPath()%>/image/border/border1/greenbarbg.gif"
                                                    colSpan=5>
                                                    <div align="left">
                                                        <img
                                                            src="<%=request.getContextPath()%>/image/border/border1/radio.gif"
                                                            width="22" height="18" border="0" align="absmiddle">
                                                        <a
                                                            href='<%=request.getContextPath()%>/page/functions/newFunction.jsp'
                                                            target="content">新增</a>
                                                        <s:if test="#request.FNo==0">
                                                            <img
                                                                src="<%=request.getContextPath()%>/image/border/border1/radio.gif"
                                                                width="22" height="18" border="0" align="absmiddle">
                                                            <a
                                                                href='<s:url action="removeModule"><s:param name="m.id" value="m.id" /></s:url>'
                                                                target="content"> 刪除所屬模塊</a>
                                                        </s:if>
                                                    </div>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </td>
                            </tr>
                    </table>
                    <table width="90%" height=23 border=0 align="center" cellPadding=0
                        cellSpacing=0>
                        <tbody>
                            <tr>
                                <td vAlign=top align=left width=100 height=23>
                                    <IMG height=23
                                        src="<%=request.getContextPath()%>/image/border/border1/bottomleft.gif"
                                        width=100>
                                </td>
                                <td width="100%"
                                    background="<%=request.getContextPath()%>/image/border/border1/bottomcenter.gif"
                                    height=23>
                                    <IMG height=1
                                        src="<%=request.getContextPath()%>/image/border/border1/clear.gif"
                                        width="100%">
                                </td>
                                <td vAlign=top align=right width=100 height=23>
                                    <IMG height=23
                                        src="<%=request.getContextPath()%>/image/border/border1/bottomright.gif"
                                        width=100 border=0>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>

 

七、總結

以上只是功能模塊的代碼,還有角色、用戶、用戶角色。角色權限等模塊,這些也就僅僅是數據的增刪改查操作,只要大家用心的去寫一下就可以了。

不管是怎樣的權限管理系統遠遠要比這個復雜,這里只是為了給大家提供功能模塊的思維,僅供大家參考,詳細的實現有興趣的可以找我~我會詳細的講解。

本人也是菜鳥一枚,最后希望大家對我支持~~謝謝!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM