Open In App

Top 25 Struts Interview Questions and Answers for 2024

Last Updated : 30 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this interview preparation blog post, we will cover some commonly asked Struts interview questions and provide an in-depth overview of Struts, covering its key concepts, architecture, features, and advantages to help you ace your next interview. Whether you are a beginner looking to break into the field or a professional developer wanting to sharpen your skills, preparing for Struts interview questions is essential. Let's dive in and get you ready for success!

Basically, Struts is a powerful framework used in Java web development, offering a structured approach to building web applications. Understanding Struts is crucial for Java developers aiming to excel in web development interviews, and mastering it can open up new opportunities in your career.

So to help you and make you more confident, we have compiled a list of common Struts interview questions for beginners and professionals.

Struts-interview-Q-&-A


Basic Struts Interview Questions for Freshers

Looking to kick-start their Struts journey can benefit from mastering these fundamental interview questions. Covering topics such as Struts architecture, action classes, and form handling, these questions will help you build a solid foundation in the framework.

1. What is Struts?

Struts Framework is an open-source and easy tool to build Java Enterprise Edition (Java EE) web applications using Struts.

  • Struts framework follows the MVC pattern (model, view, and controller).
  • Also, it separates the application logic i.e. the model, the user interface i.e. the view, and the data flow between them i.e. the controller.
  • It supports and provides the Java Servlet API. Struts simplifies the development process and encourages clean code design.
  • Its primary goal is to enhance efficiency by dividing responsibilities, allowing developers to manage database interactions, present HTML pages to users, and handle data exchange easily.

For more details on Struts please refer to this article: Introduction and Working of Struts Web Framework

2. What are the key components of the Struts framework?

The components of the Struts framework are listed below:

  • Java Servlets: It handles HTTP requests and responses in Java web applications.
  • JSP (Java Server Pages): Using Java code, it dynamically generates HTML content.
  • Action Class: This class interacts with the model and implements business logic in Struts application.
  • Custom Tags: These tags used to define custom HTML tags for reusable code in JSP pages.
  • Struts Configuration File: The Struts configuration file i.e. struts-config.xml configures actions and URLs in Struts applications.

3. What are the features of Struts?

There are so many features of Struts. Some of them are listed below:

  • MVC Architecture Support
  • Supports POJO-based actions
  • Form-based Input Handling
  • Centralized Configuration
  • Tag Libraries
  • Internationalization (I18N) support
  • Supports Integration with other Technologies

For more details please refer to this article: Struts 2 Features

4. What are the core classes of a Struts application?

  • Action Servlet: This is a central controller and it handles incoming requests and dispatches those requests to appropriate action classes.
  • Action Class: This class implements the business logic to handle specific request and generates appropriate response.
  • ActionForm: It encapsulates the data from the HTML forms and then validates them by providing the bridge between the view and model.
  • ActionMapping: It maps all the incoming requests to appropriate action classes.
  • ActionForward: After executing the action, it defines the logical outcome and forwards the flow to the next view.
  • ActionMessages: During Action Execution, messages containers generated and it is used to display the feedback to the end users.
  • ActionErrors: During Form Validation, container for error messages generates. It facilitates error handling.

5. What is MVC architecture in the Struts framework?

MVC is an architectural design pattern. It stands for Model, View, and Controller.

  • Model represents the data for storing, manipulating, and retrieving purpose. In Struts, model contains all the business logic and interacts with the storage.
  • View represents presentation of the data. In Struts, JSP (Java Server Pages) implements the view layer.
  • Controller interacts between model and view. In Struts, the ActionServlet does the controller function by handling incoming requests and provides appropriate responses.

6. What is an Interceptor and what are its lifecycle methods?

Interceptor is an object and it is used to be invoked during the preprocessing and postprocessing of a request. It performs exception handling, validation, internationalization, and also it is pluggable. The lifecycle methods of interceptors are:

  • public void init(): This method id used to set up the interceptor and during initialization, it is called only once.
  • public void intercept(ActionInvocation ai): It defines how all the requests are being processes. It is executed for each request. If it returns a String, it invokes the result page, else, it calls the next interceptor or action by using the invoke() function.
  • public void destroy(): It is used only once to destroy the interceptor.

7. What is the Flow of Requests in Struts-based applications?

The Struts-based application follows MVC architecture. The flow of the requests in Struts explained below:

Flow of Struts Application


  • The user interacts with the application by sending the request to the application server.
  • Then, user's request is intercepted to the controller by the controller servlet i.e. ActionServlet which is configured in web.xml
  • The controller is responsible to map the request URL to the appropriate Action class.
  • Action class is responsible for calling the function in Model, in which all the necessary business logic has executed and it generates a response, then forwards it to the appropriate view.

8. Differentiate between Struts 1 and Struts 2.

Features

Struts 1

Struts 2

Architecture

It supports monolithic architecture.

It supports modular architecture.

Configuration

The configuration is XML based configuration and file name can be any [name].xml

Configuration file name must be struts.xml

Action Handling

Action classes is not POJO actions, we need to inherit the abstract class.

Action class is POJO actions.

Tag Libraries

It has Struts custom tag library.

It has custom HTML tags and JSP Standard Tag Library (JSTL).

Request Processing

While processing the requests, it uses the concept of RequestProcessor class.

While processing requests, it uses the concept of Interceptors.

9. What is the role of the Action class in the Struts framework?

In Struts, the Action class acts as a Controller component and it is responsible for processing the requests of users. It performs the following roles:

  • The Action class receives the incoming requests from users and handles those requests.
  • Then it uses appropriate Model which contains all the business logic to process the requests.
  • After processing the requests, the Action class provides appropriate response such as redirecting to the URL or rendering a view page.
  • Then the mapping is done to the specific URLs. It ensures that the correct Action is invoked with each incoming requests.

Struts Interview Questions for Intermediate

Intermediate Struts developers can improve their skills by answering these advanced interview questions. These questions will test your knowledge and prepare you for senior-level positions, covering topics such as Struts setup, tile configuration, and custom tag libraries, as well as more complicated scenarios such as handling exceptions and constructing custom validators.

10. What is ActionForm in Struts and how it is created?

ActionForm in Struts is a JavaBean class. It acts as a container and transfers data between the presentation layer i.e. the HTML forms and the business logic layer i.e. the Action classes. It represents a collection of data from an HTML form and it provides getters and setters to get this data.

To create an ActionForm in Struts:

  • Create a JavaBean Class: Develop a Java class that represents the form data. This class contains private member variables along with corresponding getter and setter methods.
  • Extend ActionForm: We need to extend the org.apache.struts.action.ActionForm class in a JavaBean class to inherit the standard Struts function.
  • Configure in struts-config.xml: Declare the ActionForm in struts-config.xml configuration file. Also, we need to specify its fully qualified class name.
  • Use in Actions: In Action classes, specify the ActionForm as a parameter in the execute method or as a property to automatically receive and access form data.

11. What is the struts-default package?

In the Struts configuration, the struts-default package is a pre-defined default package. It contains all the default configurations and features that are commonly used in the Struts applications. This default package provides necessary frameworks and packages and by using them, we can build web applications quickly without having to configure everything from scratch.

This package typically include default configuration for interceptors, result types, and error handling, commonly used utility classes, and resources such as CSS files or JavaScript libraries. Developers can use these defaults as it is or can customize them according to the specific application requirements.

12. What is ForwardAction in Struts?

In Struts, the ForwardAction class is used to forward total control from one location to another within the Struts application like from a JSP to a local server.

  • It is utilized when combining an existing application with Struts.
  • Based on pre-defined configurations, it helps in directing the flow of the requests to different components.

13. How action-mapping tag is used for request forwarding in Struts configuration file?

Under action-mapping tag, forwarding options are defined in Struts configuration file i.e. struts-config.xml.

  • It used to map URLs to corresponding action classes.
  • For request processing, it specifies the pattern of URL with associated action class for same.

In the below example, if we click on the hyperlink, request will be forwarded to /pages/login.jsp using the below configuration from struts configuration file:

<action-mappings>
    <action path="/login" forward="/pages/welcome.jsp">
    </action>
 </action-mappings>

14. How can Validation Errors be displayed on a JSP page?

To display all Validation errors to user on JSP page based on the validation rules defined in validation.xml file, we can use Struts tags such as <html:errors> or <html:errors/> in JSP file. During form validation, these tags are used to display automatically generated error messages.

15. How duplicate form submission can be controlled in Struts?

To control duplicate form submission, we can use Token Interceptor provided by Struts.

  • For each form submission, it generates a unique token using saveToken() method of action class, which is then validated upon the form submission.
  • It uses isTokenValid() method to check whether the token is already used or invalid, the action will not process and it will prevent the duplicate submissions.

16. How can we access Java Beans and their properties in Struts?

To access Java Beans and their properties, we can use Bean Tag Library in Struts. This is a library which can be used to access Java beans.

17. What are the two types of Validations supported by Validator Framework in Struts?

For form data validation, Validator framework is used. The Validator framework provides two types of validation:

  • Client-side Validation: This performed in user's web browser using JavaScript before submitting the form data to the server.
  • Server-side Validation: This validation is executed after the form data is submitted.

Struts Interview Questions for Experienced

In this section we have covered advanced topics such as Struts 2.x, Struts configuration with XML, and custom plugin development, these questions will push your knowledge to its limits and prepare you for leadership roles.

18. What is DynaActionForm?

DynaActionForm is a sub-class of ActionForm Class. It is used to dynamically create form beans. For form bean creation, it uses configuration files. It dynamically handles the form data without the need to create a separate form bean class for each HTML form.

19. What are ActionServlets and Why ActionServlet singleton in Struts?

In Struts, the ActionServlets are the central controller components and it manages the entire request handling process in the application. ActionServlet is singleton in Struts.

  • When the request received, it routed to the corresponding Action classes based on configured mappings.
  • It call to the process() method of RequestProcessor.
  • It handles the overall flow of control within the application.
  • ActionServlet is based on singleton design pattern because only one object needs to be created for this controller class and for each user's request multiple threads are created later.

20. What is the role of the Struts configuration file (struts-config.xml)?

Struts Configuration file i.e. struts-config.xml only serves as a central configuration file for the Struts applications.

  • It maps the incoming requests URLs with appropriate Action classes.
  • Mapping is done along with the global settings such as message resources and form beans.

Refer the below sample struts-config.xml file for better understanding.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
    <!-- Define action mappings -->
    <action-mappings>
        <!-- Define mappings between URLs and action classes -->
    </action-mappings>
    
    <!-- Define global settings such as form beans and message resources -->
</struts-config>

21. What is meant by the validate() and reset() function in Struts?

  • validate(): This function is used to perform server-side validation of form inputs based on the validation rules defined in the ActionForm class.
  • reset(): This function determines whether to reset or delete form fields to their default values.

22. What are the condition for actionForm to work correctly?

ActionForm should follow the following conditions to work correctly.

  • ActionForm must have a no argument constructor.
  • For all properties, it should have public getter and setter methods.
  • It needs to extend the org.apache.struts.action.ActionForm class or it can implement the org.apache.struts.action.ActionForm interface.
  • It must be declared in the struts-config.xml file with a unique name and linked to the corresponding Action mapping.

23. What are OGNL and ValueStack in Struts?

OGNL stands for Object Graph Navigation Language. It is an expression language of Struts2. ValueStack is a stack and it contains all values and action specific object with data linked to actions. The values or data of ValueStack are changed through OGNL library.

For more details please refer to this article: Struts 2 OGNL

24. How Client side validation is enables on a JSP form?

To enable client-side validation in Struts, we need to enable the validator plug-in inside the struts configuration file i.e. struts-config.xml. By adding the below configurations in struts-config.xml file, this process can be done.

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathname"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

Now, the validation rules are defined in validation.xml file. Let's see a simple example, if a form contains email field, and we want to do client side validation on email field, following code will be added in validation.xml file:

<form name="gfgForm">
<field property="email"
depends="required">
<arg key="gfgForm.email"/>

25. What is declarative exception handling in Struts?

  • In Struts, when the logic for exception handling has defined within the action tag or in struts-config.xml file, it is known as declarative exception handling.
  • For this, we can specify how to handle specific exceptions thrown by actions like redirecting to different actions or displaying custom error pages etc. in struts configuration file.

Conclusion

In this free interview preparation guide, we have covered a wide range of Struts interview questions and answers to help you excel in your next interview. From basic concepts to advanced topics, these questions have been carefully selected to assess your knowledge and understanding of the Struts framework.


Similar Reads

Active Directory Interview Questions - Top 50+ Questions and Answers for 2024
Active Directory (AD) is a crucial component of modern enterprise IT infrastructure, providing centralized authentication, authorization, and directory services for Windows-based networks. As organizations continue to rely heavily on AD for managing user identities, access controls, and network resources, the demand for skilled AD administrators an
15+ min read
Teacher Interview Questions - Top 70 Questions and Answers for 2024
Teaching is a noble profession that requires a unique blend of knowledge, skills, and passion. As educators, teachers play a crucial role in shaping the minds of future generations, fostering critical thinking, and nurturing the potential of each student. In today's rapidly evolving educational landscape, teachers must be prepared to meet diverse c
15+ min read
How to Create a Project using Spring and Struts 2?
Prerequisites: Introduction to Spring FrameworkIntroduction and Working of Struts Web Framework In this article, we will discuss how the Spring framework can be integrated with the Struts2 framework to build a robust Java web application. Here I am going to assume that you know about Spring and Struts2 framework. The first question that will come t
6 min read
Spring - Integration of Spring 4, Struts 2, and Hibernate
In modern Java web application development, integrating different frameworks is a common requirement to leverage the strengths of each framework. Spring, Struts, and Hibernate are three popular frameworks that can work together seamlessly to build robust and scalable applications. In this article, we will explore how to integrate Spring 4, Struts 2
4 min read
Difference Between Struts and Spring MVC
When developing Java-based web applications, choosing between Struts and Spring MVC is crucial for ensuring scalability and maintainability. Both frameworks follow the Model-View-Controller (MVC) architecture, but they differ in their approach and flexibility. Struts, an older and once-dominant framework, was widely used for enterprise applications
5 min read
Struts 2 Features
Struts is a popular open-source framework of Java for developing large scale web-applications. It provides a framework for implementing MVC-architectured applications promoting the separation of concerns between business and presentation logic. Struts is an essential framework for building J2EE (Enterprise Edition) based web apps. Struts 2 comes wi
4 min read
Struts 2 Custom Validation - Workflow Interceptor
Struts 2 allows us to design our validation logic, commonly known as custom validation, by implementing the action class's Validatable Interface. As you might expect, understanding the Validatable interface is critical for understanding Struts2 custom validation. Workflow InterceptorThe workflow interceptor verifies whether or not there are validat
3 min read
Struts 2 double validation
The Struts 2 Framework's Double Validator determines whether or not the input is double. The error message is generated if the input is not twice. The input range can also be verified using a double validator. This example shows how to check the input range using a double validator. Plain validator Syntax of double validatorThe purpose of the doubl
3 min read
Struts 2 requiredstring Validation Example
Struts 2 is a strong framework for creating Java web applications. Its strong validation system, which enables developers to verify user input easily, is one of its primary strengths. Specifically, we'll cover Struts 2 needed string validation in this post, showing you how to make sure particular fields aren't null or empty. This is an essential co
5 min read
Struts 2 OGNL
The Struts 2 OGNL determines that the data on the ValueStack may be referenced and altered using the powerful expression language known as the Object-Graph Navigation Language (OGNL). Additionally, OGNL facilitates type conversion and data transmission. The JSP Expression Language and the OGNL are quite similar. The foundation of OGNL is the notion
3 min read
Struts 2 Email Validation
EmailValidator verifies that a given String field, if not empty, has a valid email address. It is utilized. Check to ensure that the string field has a valid email address and is not empty. Struts 2 validation is specified via XML or annotations. Manual validation within the action is also feasible, and it may be integrated with XML and annotation-
3 min read
Struts 2 Int Validation
Struts 2 integer validator is used to determine whether an integer field is inside a certain range. There are two ways to use this validator, much as other Struts validators. The Field Validator verifies if the entered number falls into the defined range. Example of Struts 2 int validation C/C++ Code <validators> <!-- plain validator-->
3 min read
Struts 2 String Length Validation
The string length field validator makes sure that a string field's length, such as a password's 6–12 characters, stays within a certain range. Using the stringlength property in elements or annotation types may be applied to XML or annotations. The String will have at least that many characters if the minLength option is supplied. When the maxLengt
3 min read
Struts 2 Date Validation Example
Struts 2, a powerful web application framework for Java, offers robust support for form validation. Custom validation allows developers to enforce specific rules on user inputs, ensuring data integrity and providing meaningful error messages. In this guide, we'll delve into the world of custom validation in Struts 2 by creating a practical example.
3 min read
Struts 2 File Upload Example
The Struts 2 framework has built-in functionality for handling file uploads via "Form-based File Upload in HTML". When a file is uploaded, it is normally kept in a temporary directory, and your Action class should process or relocate it to a permanent location to prevent data loss. File uploading is possible in Struts using a pre-defined intercepto
3 min read
Spring vs Struts in Java
Struts and spring both are used to develop Java web applications. Struts were developed earlier than Spring but with enhancements in the Struts framework, both are used nowadays to develop web applications using Java. Spring FrameworkModular, portable and testable Java applications can be formed using open-source spring framework. It is a standard
2 min read
Top SDLC Interview Questions and Answers (2024)
SDLC is a very important concept in Software Development. Whole Software Development revolves around SDLC and its various models. So because of its importance, it makes SDLC a major topic for Software Development Interviews. So in this article, we will discuss some of the most important SDLC Interview Questions along with their Answers. Before goin
8 min read
Top 25 Maven Interview Questions and Answers for 2024
In this interview preparation blog post, you will explore some of the most frequently asked Maven interview questions and answers, providing you with the knowledge and confidence to succeed in your next interview. Maven is a powerful build automation tool used primarily for Java projects. Understanding Maven and its functionality is crucial for any
12 min read
Top 30 Java 8 Interview Questions and Answers for 2024
Java 8 introduced a host of powerful features that have significantly enhanced the Java programming language. Introducing new features such as Lambda Expressions, Stream API, Functional Interfaces, the new Date and Time API, and more. As a result, Java 8 skills are highly sought after by employers in the tech industry. To help you prepare for your
15+ min read
Top 50 CCNA Interview Questions and Answers for 2024
CCNA (Cisco Certified Network Associate) is a certification that proves your ability to understand, use, and manage Cisco networks. The CCNA certification provides you with the skills necessary for optimizing and administering Cisco networking resources in an organization. With this credential, you can move on to higher-level certifications such as
15+ min read
Top jQuery Interview Questions and Answers (2024)
jQuery, a fast and lightweight JavaScript library, has been a game-changer in simplifying front-end web development. known for its simplicity, ease of use, and cross-browser compatibility. jQuery is the backbone of dynamic and interactive web development, making it a favorite among top companies such as Google, Microsoft, IBM, Netflix, Twitter, and
7 min read
50+ Top Banking Interview Questions and Answers for 2024
Acing a banking career requires a blend of financial acumen, interpersonal skills, and a deep understanding of regulatory frameworks. Whether you're aspiring to enter the industry or aiming to advance within it, preparing for a banking interview demands familiarity with a diverse array of topics. From risk management and financial regulations to cu
12 min read
Top 50 Plus Networking Interview Questions and Answers for 2024
Networking is defined as connected devices that may exchange data or information and share resources. A computer network connects computers to exchange data via a communication media. Computer networking is the most often asked question at leading organizations such Cisco, Accenture, Uber, Airbnb, Google, Nvidia, Amazon, and many others. To get int
15+ min read
Top 55 BPO Interview Questions and Answers 2024
Business Process Outsourcing (BPO) plays a pivotal role in enabling organizations to streamline operations, enhance efficiency, and focus on core competencies. The BPO industry encompasses a wide range of services, from customer support and technical assistance to back-office functions such as finance, accounting, and human resources. This dynamic
15+ min read
Top 50+ Python Interview Questions and Answers (Latest 2024)
Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify, and many more because of its performance and its powerful libraries. To get into these companies and organizations as a Python developer, you need to master some important Python Interview Questions to crack their Python O
15+ min read
Top Infosys Interview Questions and Answers For 2024
Are you preparing for an interview with Infosys? Whether you're aspiring to be a Software Engineer, System Engineer, Data Scientist, or Cybersecurity Specialist, this comprehensive guide will help you navigate the types of questions you might face and how to answer them effectively. Infosys, a global leader in consulting, technology, and next-gener
13 min read
Top 30 Plus Advanced Java Interview Questions and Answers 2024
Java is one of the most widely used programming languages worldwide, driving innovation in enterprise solutions, mobile applications, and web development. Mastering Advanced Java is essential for aspiring Java Backend Developers in today's competitive tech landscape. This article presents a comprehensive set of Advanced Java Interview Questions and
15+ min read
Top 50 C Coding Interview Questions and Answers (2024)
C is the most popular programming language developed by Dennis Ritchie at the Bell Laboratories in 1972 to develop the UNIX operating systems. It is a general-purpose and procedural programming language. It is faster than the languages like Java and Python. C is the most used language in top companies such as LinkedIn, Microsoft, Opera, Meta, and N
15+ min read
Top 50 Manual Testing Interview Questions and Answers (2024 Updated)
Manual testing is key to the software development process, as it helps identify usability and interface issues that automated tests might miss. Top companies like Uber, Google, Netflix, and Amazon use it to ensure a smooth user experience. In this interview preparation guide, we provide you with the top 50 Manual Testing interview questions for bot
15+ min read
Top 50+ Docker Interview Questions and Answers (2024)
Docker is an open-source platform that simplifies the deployment, scaling, and management of applications using lightweight containers. It has transformed the way apps are built, shipped, and deployed, becoming a key tool for many top companies like Uber, Airbnb, Google, Netflix, and Amazon. Docker is popular for its efficiency, scalability, and ea
15+ min read
three90RightbarBannerImg