Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Use of @Before and @After annotation with example..

    i have this code but not getting how to use @Before and @After annotation in struts2
    please help me
    Java Code:
    package com.tutorialspoint.struts2;
    import javax.naming.AuthenticationException;
    
    
    import com.opensymphony.xwork2.ActionSupport;
    import com.opensymphony.xwork2.interceptor.annotations.Before;
    import com.opensymphony.xwork2.validator.annotations.*;
    
    
    public class Employee extends ActionSupport{
       private static final String FAILURE = "failure";
    private String name;
       private int age;
    
       @Before
       public void isAuthorized() throws AuthenticationException {
    	   System.out.println("in is authorized methods");
       }
    
       public String execute() 
       {
           return SUCCESS;
       }
    
       @RequiredStringValidator( message = "The name is required")
       public String getName() {
           return name;
       }
       public void setName(String name) {
           this.name = name;
       }
    
       @IntRangeFieldValidator(message = "Age must be in between 28 and 65",
                                          min = "29", max = "65")
       public int getAge() {
           return age;
       }
       public void setAge(int age) {
           this.age = age;
       }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Use of @Before and @After annotation with example..

    Exactly as the example on the Struts site.
    You would tag the method you want to run.
    In this case you would check the person accessing this action was authorised to.
    Now this could be part of a parent action that all your other ones extend, thus ensuring this authorisation is done for all bits of your app.

    Similarly with the After. You might have some standard post-processing to do on a model (maybe some standard data that appeasr on each page?).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Re: Use of @Before and @After annotation with example..

    Ya i got it..but in given example what should i write in isAuthorized method..
    can you please give me example of simple code or what can i do in that method....?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: Use of @Before and @After annotation with example..

    That's entirely down to how your system is going to work.
    You'd need to design some form of authorisation mechanism to go with an authentication mechanism.
    It's an example of the sort of thing that could go there...it's not intended as a copy and paste "use this code".
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Re: Use of @Before and @After annotation with example..

    so can you explain me by example ..
    By flow of process in application and explain me that how @before and @after can be used in that process..?
    Thank you tolls for reply

Similar Threads

  1. what is annotation? what is the use?
    By java_no1 in forum New To Java
    Replies: 2
    Last Post: 06-03-2011, 04:45 PM
  2. @Override Annotation
    By Unsub in forum New To Java
    Replies: 2
    Last Post: 01-30-2010, 03:06 PM
  3. image annotation
    By rahaman.athiq in forum AWT / Swing
    Replies: 0
    Last Post: 11-19-2008, 09:03 AM
  4. Image annotation
    By rahaman.athiq in forum AWT / Swing
    Replies: 1
    Last Post: 11-17-2008, 10:28 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •