Skip to Content

TheBlogReaders.com

Salesforce.com, PHP, MySQL, Javascript, Ajax, Htacces

Struts2 Interview Questions and Answers For Graduates Part-5

Be First!

struts 241.What is the purpose of @Result annotation?
The @result annotations have the name that correspond to the outcome of the execute method. They also contain a location as to which view should be served corresponding to return value from execute().

@Result(name=”success”, value=”/success.jsp”)
public class Employee extends ActionSupport{

}

42.What is the purpose of @Action annotation?
This is used to decorate the execute() method. The Action method also takes in a value which is the URL on which the action is invoked.

public class Employee extends ActionSupport{
private String name;
private int age;
@Action(value=”/empinfo”)
public String execute()
{
return SUCCESS;
}
}

43.What is the purpose of @After annotation?
The @After annotation marks a action method that needs to be called after the main action method and the result was executed. Return value is ignored.

public class Employee extends ActionSupport{
@After
public void isValid() throws ValidationException {
// validate model object, throw exception if failed
}
public String execute() {
// perform secure action
return SUCCESS;
}
}

44.What is the purpose of @Before annotation?
The @Before annotation marks a action method that needs to be called before the main action method and the result was executed. Return value is ignored.

public class Employee extends ActionSupport{
@Before
public void isAuthorized() throws AuthenticationException {
// authorize request, throw exception if failed
}
public String execute() {
// perform secure action
return SUCCESS;
}
}

45.What is the purpose of @BeforeResult annotation?
The @BeforeResult annotation marks a action method that needs to be executed before the result. Return value is ignored.

public class Employee extends ActionSupport{
@BeforeResult
public void isValid() throws ValidationException {
// validate model object, throw exception if failed
}
public String execute() {
// perform action
return SUCCESS;
}
}

46.What is the purpose of @ConversionErrorFieldValidator annotation?
This validation annotation checks if there are any conversion errors for a field and applies them if they exist.

public class Employee extends ActionSupport{
@ConversionErrorFieldValidator(message = “Default message”,
key = “i18n.key”, shortCircuit = true)
public String getName() {
return name;
}
}

47.What is the purpose of @DateRangeFieldValidator annotation?
This validation annotation checks that a date field has a value within a specified range.

public class Employee extends ActionSupport{
@DateRangeFieldValidator(message = “Default message”,
key = “i18n.key”, shortCircuit = true,
min = “2005/01/01”, max = “2005/12/31”)
public String getDOB() {
return dob;
}
}

48.What is the purpose of @DoubleRangeFieldValidator annotation?
This validation annotation checks that a double field has a value within a specified range. If neither min nor max is set, nothing will be done.

public class Employee extends ActionSupport{
@DoubleRangeFieldValidator(message = “Default message”,
key = “i18n.key”, shortCircuit = true,
minInclusive = “0.123”, maxInclusive = “99.987”)
public String getIncome() {
return income;
}
}

49.What is the purpose of @EmailValidator annotation?
This validation annotation checks that a field is a valid e-mail address if it contains a non-empty String.

public class Employee extends ActionSupport{
@EmailValidator(message = “Default message”,
key = “i18n.key”, shortCircuit = true)
public String getEmail() {
return email;
}
}

50.What is the purpose of @ExpressionValidator annotation?
This non-field level validator validates a supplied regular expression.

@ExpressionValidator(message = “Default message”, key = “i18n.key”,
shortCircuit = true, expression = “an OGNL expression” )

(152)

Previous
Next

Leave a Reply