Software Training Institute in Chennai with 100% Placements – SLA Institute
Share on your Social Media

Struts Interview Questions and Answers

Published On: February 15, 2025

Introduction

Apache Struts is a Java web application framework used by more people. It is meant to make it easier to develop web applications. Apache Struts uses the Model-View-Controller architecture. This helps people build applications that work well and are easy to maintain. Many companies still use Apache Struts for their web projects. So when people apply for jobs, they need to know a lot about Apache Struts. They need to understand the ideas and how Apache Struts works. This is why we have a list of Apache Struts Interview Questions and Answers. It can help freshers with Apache Struts and professional experience. It can help them learn more about Apache Struts and get better at it. This way, they can be ready for job interviews and do well. Discover our Struts Course Syllabus to begin your journey in Java web application development.

Struts Interview Questions for Freshers

1. What is the Struts Framework?

The Struts Framework is a tool that helps people make web applications using Java. It uses something called the Model-View-Controller architecture. This means it keeps the business logic separate from the user interface. The Struts Framework makes it easier to develop and maintain applications.

2. Explain the MVC Architecture in Struts.

The Struts Framework uses the MVC architecture. This divides an application into three parts:

  • Model: Handles business logic and data processing.
  • View: Displays information to users using JSP, HTML, or other presentation technologies.
  • Controller: Receives user requests, processes them, and directs them to the appropriate components.

This makes the code more organized and easier to maintain for the Struts Framework.

3. What is the role of the Controller in Struts?

The Controller acts as the central point for handling user requests in the Struts Framework. It gets the requests, processes them, and sends them to the Action class in the Struts Framework. It also decides which view to display based on the result for the Struts Framework.

4. What is an ActionServlet?

The ActionServlet is the controller part in the Struts Framework. It receives all clients, identifies the required action, and forwards the request to the corresponding Action class for processing.

5. What is an Action Class?

An Action class in the Struts Framework has the business logic. It receives data from the user and interacts with the Model layer in the Struts framework. It then returns a result that determines the next page or view to display.

6. What is an ActionForm?

The ActionForm in the Struts Framework is a container that holds user input. It gets the data from web forms. Sends it to the Action class in the Struts Framework for processing.

7. What are Struts Tags?

The Struts Framework has tags that make it easier to develop web pages. These tags include:

  • HTML Tags: Create forms, buttons, text fields, and other HTML elements.
  • Logic Tags: Handle conditional statements and looping operations.
  • Bean Tags: Access and display JavaBean properties easily.

8. How does an Action class differ from an ActionForm in Struts?

  • Action Class:
    • Contains business logic.
    • Processes requests and responses.
    • Controls application flow.
  • ActionForm:
    • Stores user input data.
    • Transfers form data to the Action class.
    • Acts as a data container.

9. What is struts-config.xml?

The struts-config.xml file in the Struts Framework is the configuration file. It sets up Action mappings, form beans, and other settings for the Struts Framework.

10. What is an Interceptor in Struts2?

An Interceptor in the Struts 2 Framework is a part that runs before or after an Action method. It helps do tasks without repeating code in the Struts 2 Framework.

11. What is OGNL (Object-Graph Navigation Language)?

OGNL is a language used in the Struts 2 Framework to access and change object properties. It makes it easier to move data between the view layer and Action classes in the Struts 2 Framework.

12. How do you handle validation in Struts?

Validation in the Struts Framework checks if user input is correct. The Struts Framework supports two ways to validate:

  • Programmatic Validation: Using the validate() method inside the ActionForm class.
  • Declarative Validation: Defining validation rules in XML files or annotations.

This helps improve data accuracy and application security.

13. What is the difference between Struts 1 and Struts 2?

  • Struts 1:
    • Requires Action classes to extend a base Action class.
    • Uses ActionServlet as the controller.
    • Actions are singleton-based.
    • Requires careful thread management.
    • More configuration-heavy.
  • Struts 2:
    • Supports POJO-based Action classes.
    • Uses Interceptors extensively.
    • Creates a new Action object for each request.
    • Naturally thread-safe.
    • Easier to develop and maintain.

14. What are Struts Tiles?

Struts Tiles in the Struts Framework is a way to create reusable page layouts. 

It divides a webpage into parts, like:

  • Header
  • Footer
  • Navigation Menu
  • Content Area

This improves consistency and reduces duplicate code across web pages.

15. What are the advantages of the Struts framework?

The Struts Framework has advantages:

  • Follows the MVC architecture
  • Separates business logic from the presentation layer
  • Provides reusable components and tag libraries
  • Simplifies web application development
  • Improves maintainability and scalability
  • Supports integration with technologies
  • Reduces development time

Learn quickly with beginner-friendly Struts tutorials and guided lessons.

Struts Interview Questions for Experienced Candidates

1. What are the core components of the Struts 2 framework?

The Struts 2 framework has important parts that work together to handle user requests and send responses. The Struts 2 framework is made up of these parts.

Core Components:

  • Action: Contains the business logic and processes user requests.
  • Interceptors: Execute tasks before and after Action execution, such as validation and logging.
  • Result: Determines which view or page should be displayed after processing.
  • ValueStack and OGNL: Store and manage application data, making it accessible to the view layer.

2. Explain the request lifecycle (flow of control) in Struts 2.

When a user interacts with a Struts 2 application, the request follows this workflow:

  • The user sends a request.
  • The request reaches the Struts filter.
  • The framework identifies the mapped Action.
  • Required Interceptors are executed.
  • The Action class processes the request.
  • A Result is generated.
  • The appropriate view is rendered.
  • The response is returned to the browser.

3. What is the difference between an Interceptor and a Servlet Filter?

  • Interceptor
    • Specific to the Struts framework.
    • Works with Action classes.
    • Used for validation, logging, and authentication.
  • Servlet Filter
    • Part of the Servlet API.
    • Works on all requests.
    • Commonly used for security and request filtering.

The Interceptor and the Servlet Filter are different.

4. What is the ValueStack?

The ValueStack is a storage area used by the Struts 2 framework to hold Action objects and application data. The ValueStack is used during request processing.

  • Benefits:
    • Simplifies data access.
    • Supports the population.
    • Works with OGNL expressions.
    • Reduces dependency between business logic and the view layer.

The ValueStack is a part of the Struts 2 framework.

5. How does Type Conversion work in Struts 2?

The Struts 2 framework automatically converts string values from HTTP requests into Java data types.

  • It converts to types like:
    • Integer
    • Double
    • Date
    • Boolean
    • List

For custom objects, developers can create custom converters. The Struts 2 framework does this conversion to make it easier to work with data.

6. How do you prevent duplicate form submissions in Struts?

To prevent form submissions, you can use the Token Interceptor.

  • Here are the steps:
    • Add <s:token /> to the form.
    • Configure the interceptor in the struts.xml file.
    • The Struts 2 framework validates the token during submission.
    • Duplicate requests are automatically rejected.
    • This is how you can prevent form submissions in the Struts 2 framework.

7. How are exceptions handled in Struts?

The Struts 2 framework supports two methods of exception handling:

  • Programmatic Handling: 
    • Uses Java try-catch blocks.
    • Handles exceptions directly in the code.
  • Declarative Handling: 
    • Configured in struts.xml.
    • Uses exception mappings.
    • Redirects users to custom error pages.

Declarative handling is generally preferred because it keeps the code cleaner.

8. What is meant by Internationalization (i18n) in Struts?

Internationalization (i18n) allows applications to support languages.

  • Features:
    • It uses resource bundle files.
    • It supports languages and regions.
    • It displays content dynamically.
  • Examples:
    • messages_en.properties
    • messages_fr.properties
    • messages_es.properties

The Struts 2 framework supports Internationalization.

9. How do you implement File Upload in Struts 2?

To implement file upload, you can use the built-in File Upload Interceptor.

  • Process:
    • Create a file upload form.
    • Configure the fileUpload interceptor.
    • Define variables in the Action class.
    • Save the uploaded file.

The Struts 2 framework makes it easy to implement file upload.

10. What is Zero Configuration?

Zero Configuration allows developers to build applications with XML configuration.

  • It uses approaches like:
    • Convention Plugin
    • Java Annotations
    • @Action
    • @Result

This approach reduces configuration effort and speeds up development.

11. How do you integrate Spring with Struts 2?

To integrate Spring with Struts 2, you can use the Struts-Spring Plugin.

  • Integration Steps:
    • Configure beans in the applicationContext.xml file.
    • Define Action classes as Spring beans.
    • Enable the Struts-Spring plugin.
    • Allow Spring to manage dependency injection.

This integration improves application scalability and maintainability.

12. How does the Request Flow work in Struts 2?

The request processing flow in Struts 2 is as follows:

  • The user sends a request.
  • The Struts filter receives the request.
  • Interceptors process the request.
  • The Action class executes business logic.
  • The Result determines the view.
  • The response is. Sent back to the browser.

The Struts 2 framework handles requests in this way.

13. What is the difference between Action and ActionSupport?

  • Action:
    • Interface in Struts 2.
    • Contains basic constants and the execute() method.
    • Requires more coding.
    • Limited functionality.
  • ActionSupport:
    • Convenience class provided by Struts 2.
    • Provides built-in features and default implementations.
    • Reduces development effort.
    • Supports validation, localization, and error handling.

Most developers prefer extending ActionSupport because it offers functionality.

14. What is the difference between Declarative and Programmatic Validation in Struts?

  • Declarative Validation:
    • Defined using XML configuration files.
    • Easy to manage and maintain.
    • Suitable for standard validation rules.
  • Programmatic Validation:
    • Implemented directly in Java code.
    • Uses the validate() method.
    • Ideal for complex business validations.

The Struts 2 framework supports both Declarative and Programmatic Validation.

15. What are the key elements of the struts.xml file?

The struts.xml file is the configuration file in the Struts 2 framework.

  • Key Elements:
    • Defines global framework settings.
    • Groups related actions and configurations.
    • Maps requests to Action classes.
    • Defines the page displayed after Action execution.
    • Configures custom interceptors.
    • Defines reusable results across multiple actions.

These elements help manage application flow and configuration.

Advance your career with our comprehensive Struts Course in Chennai.

Conclusion

In conclusion, knowing Apache Struts well can really help you do well in Java web development interviews and in projects. When you learn about things like MVC architecture, Action classes, Interceptors, ValueStack, and configuration files, you get a grasp of the framework. These Apache Struts Interview Questions and Answers are here to help beginners and experienced professionals alike learn more, get better prepared for interviews, and feel confident when interacting with Apache Struts. Receive expert career guidance from our Training and Placement Institute in Chennai.

Share on your Social Media

Just a minute!

If you have any questions that you did not find answers for, our counsellors are here to answer them. You can get all your queries answered before deciding to join SLA and move your career forward.

We are excited to get started with you

Give us your information and we will arange for a free call (at your convenience) with one of our counsellors. You can get all your queries answered before deciding to join SLA and move your career forward.