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

 


Tolal:135 Click: 1 2 3 4 5 6 7
Previous Home Next

Struts Interview Questions And Answers

Page 1

Ques: 1  What're the types of controllers?

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

Ques: 2 What is the Struts 2.0 flow?

Ans:
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.

Ques: 3 How do we config struts config file in spring configuration file?

Ans:
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; }

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

Ans:
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

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

Ques: 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?

Ans:
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.

Ques: 6 
Is Struts compatible with other Java technologies? 

Ans:
Yes. Struts is committed to supporting industry standards. Struts acts as an integrator of Java technologies so that they can be used in the "real world".

Ques: 7 
How you will enable front-end validation based on the xml in validation.xml?

Ans:
The <html:javascript> tag to allow front-end validation based on the xml in validation.xml. For example the code: <html:javascript formName="logonForm" dynamicJavascript="true" staticJavascript="true" /> generates the client side java script for the form logonForm as defined in the validation.xml file. The <html:javascript> when added in the jsp file generates the client site validation script.

Ques: 8 
Explain about the validation steps involved in validation of client side address?

Ans:
The steps which are to be carried for validating client side address they are: * Validator plug in should be enabled to the system to start the process of validation. * A message resource should be created which can display error message to the client. * Validation rules should be defined by the developer for validation. * Relevant tags should be created to generate Java script code. * The whole process of validation should be tested.

Ques: 9 
What is LookupDispatchAction?

Ans:
The LookupDispatchAction is an abstract Action that dispatches to the subclass mapped execute method. This is useful in cases where an HTML form has multiple submit buttons with the same name. The button name is specified by the parameter property of the corresponding ActionMapping.

Ques: 10 
How you will make available any Message Resources Definitions file to the Struts Framework Environment?

Ans:
Message Resources Definitions file are simple .properties files and these files contains the messages that can be used in the struts project. Message Resources definitions files can be added to the struts-config.xml file using the <message-resources /> tag. Example: <message-resources parameter="MessageResources" />

Ques: 11 
Describe the details of XML files used in the “Validator Framework”? 

Ans:
The Validator Framework uses two XML configuration files: * validator-rules.xml and * validation.xml. The validator-rules.xml defines the standard validation routines. These are reusable and used in validation.xml to define the form specific validations. The validation.xml defines the validations applied to a form bean.

Ques: 12 
Can I have an Action without a form? 

Ans:
Yes! If your Action does not need any data and it does not need to make any data available to the view or controller component that it forwards to, it doesn't need a form. A good example of an Action with no ActionForm is the LogoffAction in the struts example application.

Ques: 13 
What are the JSTL and JavaServer Faces ? 

Ans:
JSTL, the JavaServer Standard Tag Library, is a set of JSP tags that are designed to make it easier to develop Web applications. JavaServer Faces (JSF) is a specification for a new technology that promises to make it easier to write MVC applications, both for the Web and for the desktop. Both JSTL and JSF are complementary to Struts.

Ques: 14 
How can we work struts on Eclipse? What is the best plugin for this?

Ans:
Eclipse provides <add struts capabilities> option to any web project. Building struts application becomes very easy with the GUI provided and drag drop feature of struts-config file. The best plug-in available for this is My-ecllipse.

Ques: 15 
What are the disadvantages of struts?

Ans:
Disadvantages of Struts: * Bigger Learning Curve. To use MVC with Struts, you have to be comfortable with the standard JSP and servlet APIs and a large and elaborate framework that is almost equal in size to the core system. * Worse Documentation. Compared to the standard servlet and JSP APIs, Struts has fewer online resources, and many first-time users find the online Apache documentation confusing and poorly organized. * Less Transparent. Struts applications are: Harder to understand and Harder to benchmark and optimize. * Rigid Approach. The flip side of the benefit that Struts encourages a consistent approach to MVC is that Struts makes it difficult to use other approaches.

Ques: 16 
How you will save the data across different pages for a particular client request using Struts?

Ans:
You can use the session object to save the data across different pages for a particular client request using Struts. Create an appropriate instance of ActionForm that is form bean and store that form bean in session scope. So that it is available to all the pages that for a part of the request. request.getSession() session.setAttribute()

Ques: 17 
What is the purpose of tiles-def.xml file, resourcebundle.properties file, validation.xml file?

Ans:
A tiles-def.xml is used as a configuration file for an appliction during tiles development. You can define the layout, header, footer, body content for your View. The validation.xml file is used to declare sets of validations that should be applied to Form Beans. Each Form Bean you want to validate has its own definition in this file. Inside that definition, you specify the validations you want to apply to the Form Bean's fields. Instead of having hard-coded error messages in the framework, Struts Validator allows you to specify a key to a message in the ApplicationResources.properties (or resourcebundle.properties) file that should be returned if a validation fails.

Ques: 18 
Explain about token feature in Struts?

Ans:
The problem of duplicate form submission arises when a user clicks the Submit button more than once before the response is sent back. This may result in inconsistent transactions and must be avoided. In Struts this problem can be handled by using the saveToken() and isTokenValid() methods of Action class. saveToken() method creates a token (a unique string) and saves that in the user's current session, while isTokenValid() checks if the token stored in the user's current session is the same as that was passed as the request parameter.

Ques: 19 
What is the difference between Apache struts and Jakarta Struts? why there are 2 names?

Ans:
Both apache struts and jakarta struts are one and the same. Struts was originally created by Craig McClanahan and was donated to the Apache Foundation in May, 2000. Its evolve as a Jakarta Project, in early 2004 it become an official Apache Project.

Ques: 20 
What is the super class of Action and ActionForm?

Ans:
There is no immediate super class for Action and Action Form, Object class is the super class for Action and ActionForm.


Goto Page:

1 2 3 4 5 6 7
Share |

Struts Objective

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