R4R
Right Place For Right Person TM
R4R Java JSF Struts FAQs Struts Interview Questions And Answers

 


Totel:135 Click: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

Struts Interview Questions And Answers

Page 1

Questions 1  What're the types of controllers?

Answer
There are two types of Controllers in Strus. 1.Main Controller/FrontController Ex: ActionServlet 2.Application Controller Ex:Action Class

Questions 2 What is the Struts 2.0 flow?

Answer
Struts and webwork has joined together to develop the Struts 2 Framework. Struts 2 Framework is very extensible and elegant for the development of enterprise web application of any size. In this section we are going to explain you the architecture of Struts 2 Framework. Request Lifecycle in Struts 2 applications User Sends request: User sends a request to the server for some resource. FilterDispatcher determines the appropriate action: The FilterDispatcher looks at the request and then determines the appropriate Action. Interceptors are applied: Interceptors configured for applying the common functionalities such as workflow, validation, file upload etc. are automatically applied to the request. Execution of Action: Then the action method is executed to perform the database related operations like storing or retrieving data from the database. Output rendering: Then the Result renders the output. Return of Request: Then the request returns through the interceptors in the reverse order. The returning request allows us to perform the clean-up or additional processing. Display the result to user: Finally the control is returned to the servlet container, which sends the output to the user browser. The Flow of a Struts 2.0 Application The following are the sequence of steps that will happen when a Html Client makes a request to a Web Application built on top of Struts 2.0 The Client (which is usually a Html Browser) makes a Request to the Web Application. The Web Server will search for the Configuration Information that is very specific to the Web Application (taken from the web.xml file), and will identity which Boot-strap Component has to be loaded to serve the Client's Request. In Struts 2.0, this Component is going to be a Servlet Filter (whereas in Struts 1.0, the component is an Action Servlet). The Filter Servlet then finds out the Action Class for this Request that is mapped in the Configuration File. File. Before passing the Request to the Action class, the Controller passes the Request to a series of Interceptor Stack (explained later). Then the Request Object is passed on to the corresponding Action Class. The Action Class then executes the Appropriate Business Logic based on the Request and the Request Parameters. After the execution of the Business Logic, a Result ("success" or "error") is returned either in the form of String or in the form of Result Object back to the Controller. The Controller uses the Return Result to choose which View to be rendered back to the Client Application.

Questions 3 How do we config struts config file in spring configuration file?

Answer
To use the Struts Spring plugin, add the ContextLoaderPlugIn to your Struts config file (usually struts-config.xml): <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml"/> </plug-in> The "contextConfigLocation" property is the location of the Spring beans configuration file. For each action that uses Spring, you need to define the action mapping to use org.springframework.web.struts.DelegatingActionProxy and declare a matching (action "path" == bean "name") Spring bean for the actual Struts action. This is an example of an action that requires an instance of UserDatabase: <action path="/logon" type="org.springframework.web.struts.DelegatingActionProxy"> <forward name="success" path="/logon.jsp"/> </action> The corresponding Spring bean configuration: <bean id="userDatabase" class="org.apache.struts.webapp.example.memory.MemoryUserDatabase" destroy-method="close" /> <bean name="/logon" class="org.apache.struts.webapp.example.LogonAction"> <property name="userDatabase"><ref bean="userDatabase" /></property> </bean> For more information on the Spring configuration file format, see the Spring beans DTD. The Struts action org.apache.struts.webapp.example.LogonAction will automatically receive a reference to UserDatabase without any work on its part or references to Spring by adding a standard JavaBean setter: private UserDatabase database = null; public void setUserDatabase(UserDatabase database) { this.database = database; }

Questions 4 Is actionform belongs to the model or view or controller in struts?

Answer
ActionForm class is used to capture user-input data from an HTML form and transfer it to the Action Class. ActionForm plays the role of Transport Vehicle between the presentation Tire & Business Tier. Life Cycle : 1. Request received by Controller 2. Create or recycle ActionForm 3. Call reset() 4. store ActionForm in proper scope 5. populate ActionForm from Request 6. Validate the ActionForm 7. If errors found then forward back to input attribute page(configured in Action mapping in struts-config.xml) with ActionForm in scope. If no errors found then call execute() with the ActionForm. The steps would be like this (in terms of the diagram) A. Client will point to the controller B. Controller would point to action form C. Actionform would point to action class D. Action class would point to JSP? E. JSP would point to client

Answer
Yes, actionform belongs to controller. But not sure about whether it belongs to model or view.

Questions 5 what are responsibilities of a struts action class?which responsibility is view related aspect of boundary component?Does it provide any facilities for separating these view related aspects for the controller related action classes?

Answer
An Action class in the struts application extends Struts 'org.apache.struts.action.Action" Class. Action class acts as wrapper around the business logic and provides an inteface to the application's Model layer. It acts as glue between the View and Model layer. It also transfers the data from the view layer to the specific business process layer and finally returns the procssed data from business layer to the view layer. An Action works as an adapter between the contents of an incoming HTTP request and the business logic that corresponds to it. Then the struts controller (ActionServlet) slects an appropriate Action and creates an instance if necessary, and finally calls execute method. To use the Action, we need to Subclass and overwrite the execute() method. In the Action Class don't add the business process logic, instead move the database and business process logic to the process or dao layer. The ActionServlet (commad) passes the parameterized class to Action Form using the execute() method. The return type of the execute method is ActionForward which is used by the Struts Framework to forward the request to the file as per the value of the returned ActionForward object.


Goto Page:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
Share |

Struts Objective Questions And Answers

Struts Objective Questions And Answers

Struts Interview Questions And Answers

Struts Subjective Questions And Answers


R4R,Struts Objective, Struts Subjective, Struts Interview Questions And Answers,Struts,Struts Interview,Struts Questions ,Struts Answers

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R