Struts Interview Questions

Struts Interview Questions | Freshers & Experienced

  • Sharad Jaiswal
  • 05th Jul, 2021
  • 946 Followers

About Struts

Struts is another type of framework developed by utilizing the concepts of the Model View Controller (MVC) Pattern. With the help of the implementation of this concept provided by Struts, the users of Java can separate the various concerns of the application system and implementing a simple code for its interpretation.

Key Features of Struts

Below are few major features of Struts

Various Tag support

Configurable MVC components

POJO based actions

AJAX support

Integration support

Theme and Template support

Practice Best Struts Interview Questions and Answers;

Q1. What is Struts?

Struts is an open-source, Model View Controller or MVC framework that can be utilized for creating website pages that are based on java. Struts utilize different segments and packages like XML, Jakarta Packages, JavaBeans, Resource Bundles, and much more. Struts extend the Java Servlet API consists of a set of own custom tag libraries.

Q2. What is front controller in Struts?

In Struts, the Front controller is basically an ActionServlet. The front uses the concept of RequestProcessor class while processing the request and the concept of Interceptors while processing the request. The front controller handles all the requests to the web application.

Q3. How do I check the installed version Struts ?

You can check the installed version of Struts by following the given steps:

  • Open file explorer, search for struts*. jar.
  • Open struts-core. jar with a unzip tool (e.g. IZArc2Go)
  • Open the META-INF folder and open MANIFEST. MF file with a text editor.
  • There you will find Specification-Version: with the version number.

 

Q4. List few differences between spring and Struts?

Few differences between spring and Struts are as follows:

Spring:

  • It is a lightweight framework.
  • It does not support a tag library.
  • It has loosely coupled modules.

Struts:

  • It is a heavyweight framework.
  • It supports tag library directives.
  • It has tightly coupled programming modules.

Q5. List few useful annotations introduced in Struts2?

Some of the useful annotations introduced in Struts2 are:

struts2 - convention-plugin-x.y.z.jar.

asm - x.y.jar.

antlr - x.y.z.jar.

commons - fileupload-x.y.z.jar.

commons - io-x.y.z.jar.

commons - lang-x.y.jar.

commons - logging-x.y.z.jar.

commons - logging-api-x.y.jar.

 

Q6. What are the main classes which are used in Struts application?

The main classes that are used in the Struts application are as follows:

ActionServlet - It is the backbone of the whole web application.

ActionForm - It is a java bean that associates one or more ActionMappings

Action - This class is extended by the org.apache.struts.action.Action class.

Action Mapping - It is used to provide mappings for Objects to Actions.

ActionForward - It is represented as a destination for the controller, RequestProcessor, that might be directed a RequestDispatcher.forward or HttpServletResponse.sendRedirect to. 

 

Q7. What is the difference between LookupDispatchAction and DispatchAction in Struts?

The difference between LookupDispatchAction and DispatchAction in Struts can be explained as DispatchAction selects the method to execute depending on the request parameter value which is configured in the XML file. Whereas LookupDispatchAction looks into the resource bundle file and finds out the corresponding key name.

Q8. How to access Java beans and their properties in Struct Framework?

To access Java beans and their properties in Struct Framework, Struts uses the Java introspection APIs to identify the names of the actual property getter and setter methods, so your beans can provide customized method names through the use of a BeanInfo class.

Q9. What is declarative exception handling in Struts?

In Struts, Declarative Exception Handling can be stated as the procedure of handling Exceptions declaratively through the help of XML files. The way of handling the exception is specified in the XML file. The benefit of Declarative Exception Handling is if ever there is a need to change the exception handling mechanism, changes can be made to the XML file, without the need to recompile the java code.

Q10. What is ValueStack and OGNL?

In Struts, a value stack is simply a stack that contains application-specific objects such as action objects and another model object. The objects can be put in the value stack to query them and delete them. Whereas OGNL stands for Object-Graph Navigation Language, which is a powerful expression language that is used to reference and manipulate data on the ValueStack.OGNL is based on the idea of having a root or default object within the context.

Q11. What is Custom Type Converter in Struts2?

Struts has two types of converters: local type converters and global type converters. The enumeration type Gender is used in the following action. When the request parameter needs to be injected into the gender property, we must define the converter, otherwise, struts2 cannot automatically complete the type conversion.

Q12. What is the use of token interceptor in Struts2?

In Struts2, the token interceptor ensures that only one request per token is processed. This interceptor can make sure that back buttons and double clicks don't cause unintended side effects.

Q13. How is Struts 2 different from Struts 1?

Struts 1 requires Action classes to extend an abstract base class. Struts1 uses JSTL Tags and hence are limited. Whereas an Struts 2 Action may implement an Action interface, along with other interfaces to enable optional and custom services.Struts 2 provides a base ActionSupport class to implement commonly used interfaces.

Q14. What is the purpose of Struts.xml in Struct2?

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.

Q15. What is default result type in Struct?

In Struct, 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.

Q16. How to handle exceptions in Structs?

You can follow the given steps to handle exceptions in Structs:

  • Global exception handling: specifies exception mappings (exception type - view name) that apply to all action classes in a Struts package.
  • Exception handling per action: specifies exception mappings that apply to a specific action class.

Q17. What is the purpose of @Result annotation in Structs?

In Struts, @Result annotation is used to specify non-convention-based results for the Struts convention handling. It is added to a class and can be used to specify the result location for a specific result code from an action method.

Q18. What are the various tag libraries available in Struts?

The various tag libraries available in Struts are:

  • HTML Tag Library - It is used to create forms that are bound to the Struts Framework.
  • Bean Tag Library - It is used for accessing JavaBeans, properties of JavaBeans, and also for defining new JavaBeans.
  • Logic Tag Library - It allows users to execute conditional statements in JSP pages.

Q19. List the design patterns used in Struts?

There are basically three types of design patterns used in Struts:

  • Creational - These design patterns are all about class instantiation or object creation.
  • Structural - These design patterns are about organizing different classes and objects to form larger structures and provide new functionality. 
  • Behavioral - Behavioral patterns are about identifying common communication patterns between objects and realizing these patterns. 

 

Q20. What is the difference between ForwardAction and IncludeAction in Struts?

The difference between ForwardAction and IncludeAction can be stated as:

ForwardAction:

  • Forwarding to a specified URL is provided by the ForwardAction. 
  • ForwardAction is used to forward to control from one page to another page/action.
  • ForwardAction is similar to <jsp:forward>

IncludeAction:

  • The mechanism to include the specified URL contents is provided by the IncludeAction.
  • IncludeAction is used to include an action in another action.
  • Include action is similar to <jsp:include> tags of a JSP page.

About Author :

  • Author of Struts Interview Questions

    Sharad Jaiswal

    My name is Sharad Jaiswal, and I am the founder of Conax web Solutions. My tech stacks are PHP, NodeJS, Angular, React. I love to write technical articles and programming blogs.

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.