The largest Interview Solution Library on the web

Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

1.What is Struts2?

Struts2 is popular and mature web application framework based on the MVC design pattern. Struts2 is not just the next version of Struts 1, but it is a complete rewrite of the Struts architecture.
Name some of the features of Struts2.
Here are some of the great features that may force you to consider Struts2 −

  • POJO forms and POJO actions − Struts2 has done away with the Action Forms that were an integral part of the Struts framework. With Struts2, you can use any POJO to receive the form input. Similarly, you can now see any POJO as an Action class.
  • Tag support − Struts2 has improved the form tags and the new tags allow the developers to write less code.
  • AJAX support − Struts2 has recognised the take over by Web2.0 technologies, and has integrated AJAX support into the product by creating AJAX tags, that function very similar to the standard Struts2 tags.
  • Easy Integration − Integration with other frameworks like Spring, Tiles and SiteMesh is now easier with a variety of integration available with Struts2.
  • Template Support − Support for generating views using templates.
  • Plugin Support − The core Struts2 behaviour can be enhanced and augmented by the use of plugins. A number of plugins are available for Struts2..

2.What are the core components of a Struct2 based application?

The Model-View-Controller pattern in Struts2 is realized with following five core components −

  • Actions
  • Interceptors
  • Value Stack / OGNL
  • Results / Result types
  • View technologies

3.Explain the life cycle of a request in Struct2 application.?

Following is the life cycle of a request in Struct2 application −

  • User sends a request to the server for requesting for some resource i. epages.
  • The FilterDispatcher looks at the request and then determines the appropriate Action.
  • Configured interceptors functionalities applies such as validation, file upload etc.
  • Selected action is executed to perform the requested operation.
  • Again, configured interceptors are applied to do any post-processing if required.
  • Finally the result is prepared by the view and returns the result to the user.

4.What is the purpose of struts.xml in Struct2?

The struts.xml file contains the configuration information that you will be modifying as actions are developed. This file can be used to override default settings for an application, for example struts.devMode = false and other settings which are defined in property file. This file can be created under the folder WEB-INF/classes.

5.What is the purpose of constant tag in struts.xml?

The constant tag along with name and value attributes will be used to override any of the following properties defined in, like we just set struts.devMode property. Setting struts.devMode property allows us to see more debug messages in the log file.

6.What is the purpose of action tag in struts.xml?

We define action tags corresponds to every URL we want to access and we define a class with execute method which will be accessed whenever we will access corresponding URL.
Results determine what gets returned to the browser after an action is executed. The string returned from the action should be the name of a result. Results are configured per-action as above, or as a "global" result, available to every action in a package. Results have optional name and type attributes. The default name value is "success".

7.What is the purpose of struct-config.xml in Struct2?

The struts-config.xml configuration file is a link between the View and Model components in the Web Client.

8.What is the purpose of form-beans tag in struct-config.xml?

This is where you map your ActionForm subclass to a name. You use this name as an alias for your ActionForm throughout the rest of the struts-config.xml file, and even on your JSP pages.

9.What is the purpose of global-forwards tag in struct-config.xml?

This section maps a page on your webapp to a name. You can use this name to refer to the actual page. This avoids hardcoding URLs on your web pages.

10.What is the purpose of action-mappings tag in struct-config.xml?

This is where you declare form handlers and they are also known as action mappings.

11.What is the purpose of plug-in tag in struct-config.xml?

This section tells Struts where to find your properties files, which contain prompts and error messages.

12.What is the purpose of in Struct2?

This configuration file provides a mechanism to change the default behavior of the framework. Actually all of the properties contained within the configuration file can also be configured in the web.xml using the init-param, as well using the constant tag in the struts.xml configuration file. But if you like to keep the things separate and more struts specific then you can create this file under the folder WEB-INF/classes. The values configured in this file will override the default values configured in which is contained in the struts2-core-x.y.z.jar distribution.

13.What are interceptors in Struts 2?

Interceptors are conceptually the same as servlet filters or the JDKs Proxy class. Interceptors allow for crosscutting functionality to be implemented separately from the action as well as the framework. You can achieve the following using interceptors −

  • Providing preprocessing logic before the action is called.
  • Providing postprocessing logic after the action is called.
  • Catching exceptions so that alternate processing can be performed.

14.How can you create your custom interceptor in Struts 2?

Creating a custom interceptor is easy; the interface that needs to be extended is the Interceptor interface.

15.How interceptor works in Struts 2?

Actual action will be executed using the interceptor by invocation.invoke call. So you can do some pre-processing and some post-processing based on your requirement.
The framework itself starts the process by making the first call to the ActionInvocation object's invoke. Each time invoke is called, ActionInvocation consults its state and executes whichever interceptor comes next. When all of the configured interceptors have been invoked, the invoke method will cause the action itself to be executed.

16.What are Result types in Struts?

The Action class manages the application's state, and the Result Type manages the view.

17.What is defeult result type?

Default result type is dispatcher, which is used to dispatch to JSP pages.

18.What is the purpose of dispatcher result type?

The dispatcher result type is the default type, and is used if no other result type is specified. It's used to forward to a servlet, JSP, HTML page, and so on, on the server. It uses the RequestDispatcher.forward method.

19.What is the purpose of redirect result type?

he redirect result type calls the standard response.sendRedirect method, causing the browser to create a new request to the given location. We can provide the location either in the body of the element or as a element.(see0000000)

20.What is Value Stack?

The value stack is a set of several objects which keeps the following objects in the provided order −

  • Temporary Objects − There are various temporary objects which are created during execution of a page. For example the current iteration value for a collection being looped over in a JSP tag.
  • The Model Object − If you are using model objects in your struts application, the current model object is placed before the action on the value stack.
  • The Action Object − This will be the current action object which is being executed.
  • Named Objects − These objects include #application, #session, #request, #attr and #parameters and refer to the corresponding servlet scopes.

« Previous | 0 | 1 | 2 | 3 | 4 | Next »

copyright © 2014 - all rights riserved by