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:

  • 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.

Top 25 Struts Interview Questions and Answers for 2024

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.

Table of Content

  • Struts Interview Questions for Freshers
  • Struts Interview Questions for Intermediate
  • Struts Interview Questions for Experienced

Similar Reads

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

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

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

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

Contact Us