Inherits the struts2 tag to control the display permissions of page elements.

Source: Internet
Author: User
Tags tld

The permission system is implemented through the struts2 Interceptor. There are too many examples on the Internet.

Only the control on whether a connection can be displayed on the page is recorded here.

Scenario: the user does not have the permission to perform the "Modify record" operation. Therefore, the "Modify record" link should not appear on the page.

Environment: the version of struts2.1.8 does not matter.

My actual environment: eclipse3.5 + JBoss tool + ejb3 + mysql5

Steps:

1. Create a TLD file under the WEB-INF, I named it here ems-tag.tld. The content is copied from the Struts-core.jar/meta-INF/directory

 
   
   
    
     
    
   
    " permission control UI tags "
    
   
     1.0 
    
   
     EMS  
    
     /ems2-tags 
     
     
      
       
      
     
       A 
      
     
       CN. vs9. EMS. web. tags. UI. anchortag 
      
     
       JSP 
      The following 
      Code  is skipped, exactly the same as struts2 .... 
     
   
  

2. inherit the tag class: org. Apache. struts2.views. jsp. UI. anchortag

 /**  Rewritten struts2 link label
* <EMS: A action = "$ {actionurl}"> link </EMS: A>
*
* Label: determines whether the "permission" is available before executing the URL to display the execution link on the page.
* "Permission" depends on whether the user group has the permission to execute this action
*/
Public Class Anchortag Extends Org. Apache. struts2.views. jsp. UI. anchortag {
/**
* Whether authorization is passed. No by default
*/
Private Boolean Isaccess = False ;


@ Override
Public Int Doendtag () Throws Jspexception {
System. Out. println ( " Doendtag " );
If ( ! Isaccess ){
Return Skip_body;
}
Return Super . Doendtag ();
}


@ Override
Public Int Dostarttag () Throws Jspexception {
System. Out. println ( This . Action ); // Determine Based on URL

// Replace this with the specific permission judgment
Isaccess = True ;


If ( ! Isaccess ){
Return Skip_body;
}
Return Super . Dostarttag ();
}


}

3. Try it on the page

Run now,Try to switch the isaccess in the label class=True | FalseSee the results

 Other labels can also be used.  .  
Currently, I have implemented a tag and action tag. , The project is enough.
Ideas :
Pagination of pages into multiple views .
Pass < EMS : Action name = " User_list " Executeresult = " True " Namespace = " /JSON " /> Method . Dynamic combination of page Components
 <%  @ Page Language  =  "  Java  "  Contenttype  =  "  Text/html; charsets = UTF-8  "  Pageencoding  =  " UTF-8  "  %>  
<% @ Taglib prefix = " S " Uri = " /Struts-tags " %>
<% @ Taglib prefix = " EMS " Uri = " Ems2-tags " %>

< EMS : A action = " /Data/user_update.action? Entity. ID = 1 " > Modify user </ EMS : A >


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.