Struts Interview questions

Struts Interview questions
Q. What is Struts
A. Struts is a J2EE Design Pattern
Struts follows Model-View-Controller (MVC) design paradigm for application architectures. The main component of the Struts framework is the flexible control layer based on standard technologies like Java Servlets, JavaBeans, ResourceBundles, and XML, as well as various Jakarta Commons packages. Struts provides its own Controller component which can be easily be integrated with Model and View layers of other technologies. For the Model, Struts can interact with standard data access technologies, like JDBC and EJB, as well as most any third-party packages, like Hibernate, iBATIS, or Object Relational Bridge. For the View, Struts allows to integrate JavaServer Pages, including JSTL and JSF, as well as Velocity Templates, XSLT, and other presentation systems.
Q. What is ActionServlet?
A. Struts Controller class is named as ActionServlet.
It is the core of Struts Framework. The fully qualified name for this is org.apache.struts.action.ActionServlet. This Controller class is responsible for handling all the requests. It takes the requests, analyzes its type and forwards to the respective Model components.
Q. How is Struts Organized? What is the flow of control in Struts?
ActionServlet provides the "controller" in the Model-View-Controller (MVC) design pattern for web applications that is commonly known as "Model 2". This nomenclature originated with a description in the JavaServerPages Specification, version 0.92, and has persisted ever since (in the absence of a better name).
Generally, a "Model 2" application is architected as follows:
* The user interface will generally be created with server pages, which will not themselves contain any business logic. These pages represent the "view" component of an MVC architecture.
* Forms and hyperlinks in the user interface that require business logic to be executed will be submitted to a request URI that is mapped to this servlet.
* There can be one instance of this servlet class, which receives and processes all requests that change the state of a user's interaction with the application. The servlet delegates the handling of a request to a @link(RequestProcessor) object. This component represents the "controller" component of an MVC architecture.
* The RequestProcessor selects and invokes an @link(Action) class to perform the requested business logic, or delegates the response to another resource.
* The Action classes can manipulate the state of the application's interaction with the user, typically by creating or modifying JavaBeans that are stored as request or session attributes (depending on how long they need to be available). Such JavaBeans represent the "model" component of an MVC architecture.
* Instead of producing the next page of the user interface directly, Action classes generally return an @link(ActionForward) to indicate which resource should handle the response. If the Action does not return null, the RequestProcessor forwards or redirects to the specified resource (by utilizing RequestDispatcher.forward or Response.sendRedirect) so as to produce the next page of the user interface.
The standard version of RequestsProcessor implements the following logic for each incoming HTTP request. You can override some or all of this functionality by subclassing this object and implementing your own version of the processing.
* Identify, from the incoming request URI, the substring that will be used to select an action procedure.
* Use this substring to map to the Java class name of the corresponding action class (an implementation of the Action interface).
* If this is the first request for a particular Action class, instantiate an instance of that class and cache it for future use.
* Optionally populate the properties of an ActionForm bean associated with this mapping.
* Call the execute method of this Action class, passing on a reference to the mapping that was used, the relevant form-bean (if any), and the request and the response that were passed to the controller by the servlet container (thereby providing access to any specialized properties of the mapping itself as well as to the ServletContext).
Q. What all design patterns does struts implement?
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

No comments: