Friday, September 1, 2017

Struts Important Questions with Answer

Struts Important Questions with Answer


1. What design patterns are used in Struts?



Struts is based on model 2 MVC (Model-View-Controller) architecture. Struts controller uses the command design pattern and the action classes use the adapter design pattern. The process() method of the RequestProcessor uses the template method design pattern. Struts also implement the following J2EE design patterns.

Service to Worker

Dispatcher View

Composite View (Struts Tiles)

Front Controller

View Helper

Synchronizer Token

2. What are the different kinds of actions in Struts?

The different kinds of actions in Struts are:

  • ForwardAction
  • IncludeAction
  • DispatchAction
  • LookupDispatchAction
  • SwitchAction

3. Can we have more than one struts-config.xml file for a single Struts application?

Yes, we can have more than one struts-config.xml for a single Struts application. They can be configured as follows:



>actionservlet-name>



org.apache.struts.action.ActionServlet





config



/WEB-INF/struts-config.xml,

/WEB-INF/struts-admin.xml,

/WEB-INF/struts-config-forms.xml






.....

4. 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 the execute() 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

download file now