简单的权限管理

转自 http://heisetoufa.iteye.com/blog/227699

程序入口为

http://localhost:8080/ShowPermission.do

下面贴代码

ShowPermission.jsp

Html代码 复制代码
  1. <%@ page contentType="text/html; charset=gbk"%>  
  2. <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>    
  3. <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>  
  4. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
  5.     
  6. <html>    
  7.   <head>  
  8.  <title>JSP for ShowPermissionForm form</title>  
  9.   </head>  
  10. <style type="text/css">  
  11. table#list {   
  12.   border-top: 1px solid #000000;   
  13.   border-left: 1px solid #000000;   
  14.   border-collapse: collapse;   
  15.   font-size: 11pt;   
  16. }   
  17. table#list td, table#list th {   
  18.   border-bottom: 1px solid #000000;   
  19.   border-right: 1px solid #000000;   
  20.   padding-left: 5px;   
  21.   padding-right: 5px;   
  22. }   
  23. table#list thead tr {   
  24.   background-color: #0af0cd;   
  25. }   
  26. table#list td.permission {   
  27.   text-align: center;   
  28.   width: 70px;   
  29. }   
  30. </style>  
  31.      
  32.      
  33.   <body>  
  34.     <html:form action="/updatePermission" method="post">  
  35.     <table id="list" cellspacing="0">  
  36.       <thead>  
  37.         <tr>  
  38.           <td>选项</td>  
  39.           <td>姓名</td>  
  40.           <td width="100px">单位</td>  
  41.           <td width="100px">部门</td>  
  42.           <td>增加权限</td>  
  43.           <td>删除权限</td>  
  44.           <td>修改权限</td>  
  45.           <td>查看权限</td>  
  46.         </tr>  
  47.       </thead>  
  48.       <tbody>  
  49.         <c:forEach items="${emps}" var="emp">  
  50.         <tr>  
  51.           <td><input type="checkbox" name="empIds" value="${emp.empId}"></td>  
  52.           <td>${emp.name}</td>  
  53.           <td>${emp.unit}</td>  
  54.           <td>${emp.division}</td>  
  55.           <td><input type="checkbox" name="addPermissions" value="${emp.empId}"<c:if test="${emp.addPermission == '1'}"> checked</c:if> /></td>  
  56.           <td><input type="checkbox" name="deletePermissions" value="${emp.empId}"<c:if test="${emp.deletePermission == '1'}"> checked</c:if> /></td>  
  57.           <td><input type="checkbox" name="modifyPermissions" value="${emp.empId}"<c:if test="${emp.modifyPermission == '1'}"> checked</c:if> /></td>  
  58.           <td><input type="checkbox" name="viewPermissions" value="${emp.empId}"<c:if test="${emp.viewPermission == '1'}"> checked</c:if> /></td>             
  59.         </tr>  
  60.         </c:forEach>  
  61.       </tbody>  
  62.     </table>  
  63.     <html:submit value="更新" />  
  64.     </html:form>  
  65.   </body>  
  66. </html>  
Html代码 复制代码
  1. <%@ page contentType="text/html; charset=gbk"%>  
  2. <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>    
  3. <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>  
  4. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
  5.     
  6. <html>    
  7.   <head>  
  8.  <title>JSP for ShowPermissionForm form</title>  
  9.   </head>  
  10. <style type="text/css">  
  11. table#list {   
  12.   border-top: 1px solid #000000;   
  13.   border-left: 1px solid #000000;   
  14.   border-collapse: collapse;   
  15.   font-size: 11pt;   
  16. }   
  17. table#list td, table#list th {   
  18.   border-bottom: 1px solid #000000;   
  19.   border-right: 1px solid #000000;   
  20.   padding-left: 5px;   
  21.   padding-right: 5px;   
  22. }   
  23. table#list thead tr {   
  24.   background-color: #0af0cd;   
  25. }   
  26. table#list td.permission {   
  27.   text-align: center;   
  28.   width: 70px;   
  29. }   
  30. </style>  
  31.      
  32.      
  33.   <body>  
  34.     <html:form action="/updatePermission" method="post">  
  35.     <table id="list" cellspacing="0">  
  36.       <thead>  
  37.         <tr>  
  38.           <td>选项</td>  
  39.           <td>姓名</td>  
  40.           <td width="100px">单位</td>  
  41.           <td width="100px">部门</td>  
  42.           <td>增加权限</td>  
  43.           <td>删除权限</td>  
  44.           <td>修改权限</td>  
  45.           <td>查看权限</td>  
  46.         </tr>  
  47.       </thead>  
  48.       <tbody>  
  49.         <c:forEach items="${emps}" var="emp">  
  50.         <tr>  
  51.           <td><input type="checkbox" name="empIds" value="${emp.empId}"></td>  
  52.           <td>${emp.name}</td>  
  53.           <td>${emp.unit}</td>  
  54.           <td>${emp.division}</td>  
  55.           <td><input type="checkbox" name="addPermissions" value="${emp.empId}"<c:if test="${emp.addPermission == '1'}"> checked</c:if> /></td>  
  56.           <td><input type="checkbox" name="deletePermissions" value="${emp.empId}"<c:if test="${emp.deletePermission == '1'}"> checked</c:if> /></td>  
  57.           <td><input type="checkbox" name="modifyPermissions" value="${emp.empId}"<c:if test="${emp.modifyPermission == '1'}"> checked</c:if> /></td>  
  58.           <td><input type="checkbox" name="viewPermissions" value="${emp.empId}"<c:if test="${emp.viewPermission == '1'}"> checked</c:if> /></td>             
  59.         </tr>  
  60.         </c:forEach>  
  61.       </tbody>  
  62.     </table>  
  63.     <html:submit value="更新" />  
  64.     </html:form>  
  65.   </body>  
  66. </html>  
<%@ page contentType="text/html; charset=gbk"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> 
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
 
<html> 
  <head>
 <title>JSP for ShowPermissionForm form</title>
  </head>
<style type="text/css">
table#list {
  border-top: 1px solid #000000;
  border-left: 1px solid #000000;
  border-collapse: collapse;
  font-size: 11pt;
}
table#list td, table#list th {
  border-bottom: 1px solid #000000;
  border-right: 1px solid #000000;
  padding-left: 5px;
  padding-right: 5px;
}
table#list thead tr {
  background-color: #0af0cd;
}
table#list td.permission {
  text-align: center;
  width: 70px;
}
</style>
  
  
  <body>
    <html:form action="/updatePermission" method="post">
    <table id="list" cellspacing="0">
      <thead>
        <tr>
          <td>选项</td>
          <td>姓名</td>
          <td width="100px">单位</td>
          <td width="100px">部门</td>
          <td>增加权限</td>
          <td>删除权限</td>
          <td>修改权限</td>
          <td>查看权限</td>
        </tr>
      </thead>
      <tbody>
        <c:forEach items="${emps}" var="emp">
        <tr>
          <td><input type="checkbox" name="empIds" value="${emp.empId}"></td>
          <td>${emp.name}</td>
          <td>${emp.unit}</td>
          <td>${emp.division}</td>
          <td><input type="checkbox" name="addPermissions" value="${emp.empId}"<c:if test="${emp.addPermission == '1'}"> checked</c:if> /></td>
          <td><input type="checkbox" name="deletePermissions" value="${emp.empId}"<c:if test="${emp.deletePermission == '1'}"> checked</c:if> /></td>
          <td><input type="checkbox" name="modifyPermissions" value="${emp.empId}"<c:if test="${emp.modifyPermission == '1'}"> checked</c:if> /></td>
          <td><input type="checkbox" name="viewPermissions" value="${emp.empId}"<c:if test="${emp.viewPermission == '1'}"> checked</c:if> /></td>          
        </tr>
        </c:forEach>
      </tbody>
    </table>
    <html:submit value="更新" />
    </html:form>
  </body>
</html>

 ShowPermissionAction

Java代码 复制代码
  1. /*  
  2.  * Generated by MyEclipse Struts  
  3.  * Template path: templates/java/JavaClass.vtl  
  4.  */  
  5. package com.struts.action;   
  6.   
  7. import java.util.ArrayList;   
  8. import java.util.List;   
  9.   
  10. import javax.servlet.http.HttpServletRequest;   
  11. import javax.servlet.http.HttpServletResponse;   
  12. import org.apache.struts.action.Action;   
  13. import org.apache.struts.action.ActionForm;   
  14. import org.apache.struts.action.ActionForward;   
  15. import org.apache.struts.action.ActionMapping;   
  16.   
  17. import com.bean.Employee;   
  18.   
  19. public class ShowPermissionAction extends Action {   
  20.   
  21.     public ActionForward execute(ActionMapping mapping, ActionForm form,   
  22.             HttpServletRequest request, HttpServletResponse response) {   
  23.         List<Employee> emps = new ArrayList<Employee>();   
  24.         Employee emp1 = new Employee("001""Enjoy",   "单位""工程部""0""1""1""0");   
  25.         Employee emp2 = new Employee("002""joejoe",   "单位""工程部""1""0""0""0");   
  26.         Employee emp3 = new Employee("003""koko",   "单位""工程部""1""1""1""0");   
  27.         Employee emp4 = new Employee("004""pizzame",   "单位""工程部""1""0""1""1");   
  28.         Employee emp5 = new Employee("005""heisetoufa",  "单位""工程部""1""1""0""0");   
  29.         emps.add(emp1);   
  30.         emps.add(emp2);   
  31.         emps.add(emp3);   
  32.         emps.add(emp4);   
  33.         emps.add(emp5);   
  34.            
  35.         for(Employee emp : emps) {   
  36.             System.out.println(emp);   
  37.         }   
  38.            
  39.         request.setAttribute("emps", emps);   
  40.         return mapping.findForward("showPermission");   
  41.     }   
  42. }  
Java代码 复制代码
  1. /*  
  2.  * Generated by MyEclipse Struts  
  3.  * Template path: templates/java/JavaClass.vtl  
  4.  */  
  5. package com.struts.action;   
  6.   
  7. import java.util.ArrayList;   
  8. import java.util.List;   
  9.   
  10. import javax.servlet.http.HttpServletRequest;   
  11. import javax.servlet.http.HttpServletResponse;   
  12. import org.apache.struts.action.Action;   
  13. import org.apache.struts.action.ActionForm;   
  14. import org.apache.struts.action.ActionForward;   
  15. import org.apache.struts.action.ActionMapping;   
  16.   
  17. import com.bean.Employee;   
  18.   
  19. public class ShowPermissionAction extends Action {   
  20.   
  21.     public ActionForward execute(ActionMapping mapping, ActionForm form,   
  22.             HttpServletRequest request, HttpServletResponse response) {   
  23.         List<Employee> emps = new ArrayList<Employee>();   
  24.         Employee emp1 = new Employee("001""Enjoy",   "单位""工程部""0""1""1""0");   
  25.         Employee emp2 = new Employee("002""joejoe",   "单位""工程部""1""0""0""0");   
  26.         Employee emp3 = new Employee("003""koko",   "单位""工程部""1""1""1""0");   
  27.         Employee emp4 = new Employee("004""pizzame",   "单位""工程部""1""0""1""1");   
  28.         Employee emp5 = new Employee("005""heisetoufa",  "单位""工程部""1""1""0""0");   
  29.         emps.add(emp1);   
  30.         emps.add(emp2);   
  31.         emps.add(emp3);   
  32.         emps.add(emp4);   
  33.         emps.add(emp5);   
  34.            
  35.         for(Employee emp : emps) {   
  36.             System.out.println(emp);   
  37.         }   
  38.            
  39.         request.setAttribute("emps", emps);   
  40.         return mapping.findForward("showPermission");   
  41.     }   
  42. }  
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.struts.action;

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

import javax.servlet.http.HttpServletRequest;
import javax.servlet.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值