日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Struts2的interceptor實現(xiàn)權(quán)限管理

這是以前寫過的一個利用struts2的interceptor進行權(quán)限管理的筆記,以前是放電腦上的,今天偶然看到了,就貼出來,希望能對有需要的人有點幫助,同時自己以后需要看的時候也會更加方便點!

說明一點:這個interceptor里面的代碼是根據(jù)我特定的項目寫的,所以請有需要的人不要盲目的照搬!

自己寫一個interceptor,該interceptor繼承interceptor接口,實現(xiàn)其中的intercept方法;然后在struts.xml

中進行配置,并把該interceptor置于默認的interceptor中,注意,這里在設(shè)置默認的intercept的時候

一定要加上原來的intercept,否則原來的就不可以用了,就不能用struts2了,具體來說是這樣:

Xml代碼

 
 
  1.     
  2.         
  3.         
  4.             
  5.             
  6.         
  7.     
  8.     

 

Java代碼

 
 
  1. @Override    
  2.     public String intercept(ActionInvocation invoke) throws Exception {     
  3.         // TODO Auto-generated method stub     
  4.         HttpSession session  = ServletActionContext.getRequest().getSession();     
  5.         ApplicationContext context = Util.getContext(ServletActionContext.getServletContext());     
  6.         PriorityService priorityService = context.getBean(PriorityService.class);     
  7.              
  8.         String actionName = invoke.getProxy().getActionName();     
  9.         String methodName = invoke.getProxy().getMethod();     
  10.         if ("execute".equals(methodName))      
  11.             methodName = "index";     
  12.         int index = actionName.indexOf("/");     
  13.         String name = actionName.substring(0, index);     
  14.              
  15.         Priority priority = priorityService.find(name, methodName);     
  16.         Object obj = session.getAttribute("user");     
  17.         if (obj != null) {     
  18.             User currentUser = (User) obj;     
  19.                  
  20.             ModuleService moduleService = context.getBean(ModuleService.class);     
  21.             Module module = moduleService.findByUrl(name+"/"+methodName);     
  22.             if (module != null) {     
  23.                 SystemDiaryService sdService = context.getBean(SystemDiaryService.class);     
  24.                 SystemDiary diary = new SystemDiary();     
  25.                 diary.setOperator(currentUser);     
  26.                 diary.setOperateModule(module.getName());     
  27.                 sdService.add(diary);     
  28.             }     
  29.                  
  30.             if (priority != null) {     
  31.                 boolean hasPermission = currentUser.hasPermission(priority);     
  32.                      
  33.                 if (!hasPermission) {     
  34.                     return "forbidden";     
  35.                 }     
  36.             }     
  37.         }     
  38. //      System.out.println("name = "+name + "**actionName = "+actionName+"*methodName = "+methodName);     
  39.     
  40.         String result = invoke.invoke();     
  41.         return result;     
  42.     }  

分享題目:Struts2的interceptor實現(xiàn)權(quán)限管理
網(wǎng)站URL:http://www.5511xx.com/article/djecioc.html