Thursday, September 1, 2011

struts-interview-question-answer-question

Ques: 1 What is struts?
Ans:The Jakarta struts project, an open source project supported by the Apache software Foundation, is a server side java implementation of the modetl view controller (MVC) design pattern.

The struts framework designed to create Web application that easily separate the presentation layer and allow it to be abstracted from the transaction and data layers.
Ques: 2 

What are the various steps involved in the implementaion of struts?
Ans:The struts framwork models its server side implementation of the MVC using a combination of JSPs, custom JSP tags, and a Java Servlet. It involves the following steps :



* The incoming request is received by the ActionServlet, which acts as the controller, and the ActionServlet looks up the requested URI in an XML file.

* The ActionClass performs its logic on the Model components associated with the application.

* Once the Action has completed its processing, it returns control to the ActionServlet with a key that indicates the result of its processing. ActionServlet uses this key to determine where this result should be forwarded for presentation.

* The request is complete when the ActionServlet response by forwarding the request ot the view that was linked to the returned key, and this view presents the result of the Action.
Ques: 3 What is MVC design pattern?
Ans:MVC stands for Model-View-Controller. The MVC design pattern is originated from Smalltalk, consists of three components : a Model, a View, and a Controller.



MODEL : Represents the data objects. The Model is what is being manipulated and persented to the user. Model contains the business logic of the application.



VIEW : Serves as screen representation of the Model. It is the object that represents the current state of the objects.



CONTROLLER : Defines the way the user interface reacts to the user's input. The Controller component is the object that manipulates the Model, or data object.
Ques: 4 How will you install struts framework in your web application?
Ans:The follwing steps are involved to install struts framework in your web application :



* Uncompress the Struts Archive to your local disk.

* Create a new web Application say, MyStrutsApp inside the webapps directory under the tomcat directory.

* Copy all the jar files, extracted from the lib directory into the /webapps/MyStrutsApp/WEB-INF/lib directory.

* Create an empty web.xml file and copy it to the /webapps/MyStrutsApp/WEB-INF/ directory.

* Create an empty struts-config.xml file and copy it to the /webapps/MyStrutsApp/WEB-INF/ directory. The struts-config.xml file is the diployment descriptor for all Struts applicattion. It is the file that glues all of the MVCcomponents together.
Ques: 5 Describe the struts specific form tag?
Ans:Instead of using the standard HTML Form tag, like most HTML pages, the struts specific Form tag is : 





..........




This tag with its subordinate input tags, encapsulates Struts form processing. The Form tag attributes are :

* action : Represents the URL to which this form will be submitted. This is also used to find the appropriate ActionMapping in the Struts configuration file.

* name : Identifies the key that is used to lookup the appropriate ActionForm that will represent the submitted form data.

* type : Names the fully qualified classname of the form bean you want to use in this request.



To use the struts specific tag you have to use the taglib directive:

<%@ taglib uri="WEB-INF/struts-html.tld" prefix="html" %>
Ques: 6 What is ActionForm in the struts?
Ans:When an  is submitted, the Struts framework populates the matching data members of the ActionForm with the values entered in the  tag. The Struts framework does this by using JavaBean introspection. This is all done by the class specified in the type attribute of the  tag. This class will extends the org.apache.struts.action.ActionForm, as must all ActionForm objects with a get and set accessor that match its data members.
Ques: 7 What are the parameters used in the Action.execute() method in the Struts.
Ans:The following parameters are used in the Action.execute(...) method :

* ActionMapping : The ActionMapping class contains all of the deployment information for a particular Action object. This class is used to determine where the result of the class (that extends the Action class) will be sent once its processing is complete.

* ActionForm : Represents the form inputs cntaining the request parameters from the view referencing this Action bean.

* HttpServletRequest : Reference to the current Http request object.

* HttpServletResponse : Reference to the current Http response object.
Ques: 8 Which mathod is use to forward the result to the appropriate view in the Action class in Struts?
Ans:The findForward() method is use to forward the result to the appropriate view in the Action class. This method takes the paremeter name for the view file to which the result is being forwarded.
Ans:ActionMapping Class's findForward(String) method...

in ActionClass ActionMapping is Passed as Parameter so we do not need to create Seprate instance for that ......
Ques: 9 How will you tell the web application and container about your ActionServlet?
Ans:This can be accomplished by adding the following servlet definition to the web.xml file :





action

org.apache.struts.action.ActionServlet



config/WEB-INF/struts-config.xml


1




Once you told the container about the ActionServlet you need to tell it when it should be executed by adding element in web.xml file :





action

*.do




This mapping tells the web application that whenever a request is received with .do appended to the URL then the servlet named action should service the request.
Ques: 10 

What are the various struts controller components?
Ans:Four distinct Struts Controller components:

* The ActionServlet class

* The Action class

* Plugins

* RequestProcesser
Ques: 11 

What is ActionServlet class in the struts controller?
Ans:The org.apache.struts.action.ActionServlet is the backbone of all Struts application. It is the main controller component that handles the client request and determines which org.apache.struts.action.Action will process each received request. It serves as an Action factory - creating specific Action classes based on the user's request.
Ques: 12 What is the entry point to ActionServlet when a request comes in.
Ans:The two main entry point into the ActionServlet are the same as any other servelt : doGet() and doPost().

They call single method named process(). The struts specific behaviour begin with this mehtod.
Ques: 13 What is the process() method doing in the ActionServlet class?
Ans:The process() method gets the current RequestProcessor and invokes the RequestProcessor.process() method.The RequestProcessor.process() method is where the current request is actually serviced. This method retrieves from the struts-config.xml file, the  element that matches the path submitted on the request. It does this by matching the path passed in the  tag's action element to the  element with the same path value.
Ques: 14 Who calls the ActionForm.validate() method inside the ActionServlet.
Ans:The RequestProcessor.process() method calls the ActionForm.validate() method, which checks the validity of the of the submitted values.
Ques: 15 What is for Action.execute() method?
Ans:The execute method is where your application logic begins. It is the method that you need to override when defining your own Actions. The execute() method has two functions:

* It performs the user-defined business logic associated with your application.

* It tells the Framework where it should next route the request.



The Struts framework defines two execute() methods. The first execute() implementation is used when you are defining custom Actions that are not HTTP specific, i.e. anlogous to the javax.servlet.GenericServlet class. The second, HTTP specific, You need to override the Action.execute() method and is anlogous to the javax.servlet.HttpServlet class.

Its signature is:



public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpResponse response) throws IOException, ServletException{// some code here}
Ques: 16 

Describe the purpose of the Action class?
Ans:The org.apache.struts.action.Action class is a most common component of the Struts Controller. This class must be extended for each specialized Struts function in your application. The collection of these Action classes is what defines your web application.

To develop your own Action class, you must complete the following steps:

* Create a class that extends the org.apache.struts.action.Action class.

* Implement the appropriate execute() method and add your specific business logic.

* Compile the new Action and move it to the Web application's classpath, i.e. /WEB-INF/classes directory.

* Add an element to the application's struts-config.xml file describing the new Action.
Ques: 17 What are Struts Plugins?
Ans:Struts Plugins are modular extensions to the Struts COntroller. They are defined by the org.apache.struts.action.Plugin interface.  Struts Plugins are useful are useful when you are allocating resources or preparing connections to the databases or even JNDI resources.

This interface defines two lifecycle mathods: init() and desstroy().
Ques: 18 

What are the steps involved in Struts Plugins?
Ans:All Plugins must implement the two Plugin methods init() and destroy(). To develop your own Plugin You must complete the following steps:

* Create a class that implements the org.apache.struts.action.Plugin interface.

* Add a default empty contructor to the Plugin implementation. You must have a default constructor to ensure that the ActionServlet property creates your Plugin.

* Implement both the init() and destroy() methods and your implementation.

* Compare the new Plugin and move it into the web applocation's classpath.

* Add a element to the application's struts-config.xml file describing the new Plugin.
Ques: 19 What is RequestProcessor? How will you create your own RequestProcessor? 
Ans:The RequestProcessor is the class that you need to override when you want to customize the processing of the ActionServlet. It contains a predefined entry point that is invoked by the Struts controller with each request. The entry point is the processPreprocess() method.

Steps involved in creation your own RequestProcessor:

* Create a class that extends the org.apache.struts.action.RequestProcessor class.

* Add a default empty constructor to the RequestProcessor implementation.

* Implement your processPreprocess() method.
Ques: 20 

How will you configure the Plugin in your web application.
Ans:To deploy and configure your Plugin class, you must:

* Compile and move the Plugin class file into your application's WEB-INF/classes/ directory.

* Add a element to your struts-config.xml file. For example:



The element should be the last element in the struts-config.xml file.

* Restart the Web application.

No comments:

Post a Comment