Results 1 to 5 of 5
- 09-07-2012, 07:52 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 3
- Rep Power
- 0
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; } }
- 09-07-2012, 09:50 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 09-07-2012, 10:50 AM #3
Member
- Join Date
- Aug 2012
- Posts
- 3
- Rep Power
- 0
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....?
- 09-07-2012, 02:28 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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.
- 09-07-2012, 04:38 PM #5
Member
- Join Date
- Aug 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
what is annotation? what is the use?
By java_no1 in forum New To JavaReplies: 2Last Post: 06-03-2011, 03:45 PM -
@Override Annotation
By Unsub in forum New To JavaReplies: 2Last Post: 01-30-2010, 02:06 PM -
image annotation
By rahaman.athiq in forum AWT / SwingReplies: 0Last Post: 11-19-2008, 08:03 AM -
Image annotation
By rahaman.athiq in forum AWT / SwingReplies: 1Last Post: 11-17-2008, 09:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks