Friday 4 May 2012

Struts interview questions 5


21.What is DispatchAction?
The DispatchAction class is used to group related actions into one class. Using this class, you can have a method for each logical action compared than a single execute method. The DispatchAction dispatches to one of the logical actions represented by the methods. It picks a method to invoke based on an incoming request parameter. The value of the incoming parameter is the name of the method that the DispatchAction will invoke.

22.How to use DispatchAction?
To use the DispatchAction, follow these steps :
  • Create a class that extends DispatchAction (instead of Action)
  • In a new class, add a method for every function you need to perform on the service – The method has the same signature as theexecute() method of an Action class.
  • Do not override execute() method – Because DispatchAction class itself provides execute() method.
  • Add an entry to struts-config.xml
 23.What is the use of ForwardAction?
The ForwardAction class is useful when you’re trying to integrate Struts into an existing application that uses Servlets to perform business logic functions. You can use this class to take advantage of the Struts controller and its functionality, without having to rewrite the existing Servlets. Use ForwardAction to forward a request to another resource in your application, such as a Servlet that already does business logic processing or even another JSP page. By using this predefined action, you don’t have to write your own Action class. You just have to set up the struts-config file properly to use ForwardAction.

24.What is IncludeAction?
The IncludeAction class is useful when you want to integrate Struts into an application that uses Servlets. Use the IncludeAction class to include another resource in the response to the request being processed.

25.What is the difference between ForwardAction and IncludeAction?
The difference is that you need to use the IncludeAction only if the action is going to be included by another action or jsp. UseForwardAction to forward a request to another resource in your application, such as a Servlet that already does business logic processing or even another JSP page.

No comments:

Post a Comment