Struts Interview Questions and Answers

Last Updated : 31 Jul, 2026

Struts is a popular Java-based MVC framework used for building enterprise web applications and is a common topic in Java web development interviews. Interviewers often ask Struts questions to evaluate a candidate's understanding of the MVC architecture, framework components, request processing, and integration with enterprise technologies.

  • Covers the most commonly asked Struts interview questions with clear and concise answers.
  • Includes topics ranging from Struts fundamentals to advanced concepts, validation, configuration, interceptors, and real-world applications.

Struts Interview Questions for Freshers

1. What is Struts?

Apache Struts is an open-source Java web application framework used to develop enterprise-level web applications. It follows the Model-View-Controller (MVC) architecture, which separates business logic, presentation, and request handling, making applications easier to develop and maintain.

  • It supports and provides the Java Servlet API. Struts simplifies the development process and encourages clean code design.
  • Separates business logic, presentation, and controller logic.
  • Simplifies the development of enterprise web applications.
  • Provides built-in support for validation, form handling, and navigation

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

The Struts framework follows the Model-View-Controller (MVC) architecture and consists of several components that work together to process user requests and generate responses.

  • ActionServlet (Controller): Receives client requests, processes them, and forwards them to the appropriate action class.
  • Action Class (Model): Contains the business logic and interacts with the service or database layer to process user requests.
  • ActionForm: Stores user input from HTML forms and transfers it between the view and the controller.
  • JSP & Struts Configuration (struts-config.xml): JSP pages act as the View to display data, while struts-config.xml defines mappings between actions, forms, and views.

3. What are the features of Struts?

Struts is an open-source Java web framework that simplifies the development of enterprise web applications by implementing the MVC (Model-View-Controller) architecture. It provides built-in support for request handling, form validation, and reusable components.

  • MVC Architecture: Separates the application into Model, View, and Controller, making the code organized and easier to maintain.
  • Built-in Validation: Provides validation frameworks to validate user input before processing requests.
  • Custom Tag Libraries: Includes JSP tag libraries that reduce Java code in JSP pages and simplify UI development.
  • Centralized Configuration: Uses configuration files (such as struts-config.xml in Struts 1 or annotations/XML in Struts 2) to manage request mappings and application flow.
  • Reusable Components: Encourages reusable actions, forms, and business logic, reducing code duplication.

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

The core classes of a Struts application are responsible for handling client requests, executing business logic, managing forms, and generating the appropriate response. Together, they implement the MVC architecture and simplify web application development.

  • 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 (Model-View-Controller) is a design pattern used by the Struts framework to separate an application into three independent components: Model, View, and Controller. This separation improves code organization, maintainability, reusability, and scalability.

  • 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 Action class in Struts?

An Action class is a controller component in the Struts framework that processes client requests, executes the required business logic, and returns the appropriate response. It acts as a bridge between the presentation layer (View) and the business layer (Model).

  • Interacts with the Model to retrieve or update data.
  • Returns the appropriate result or view (such as a JSP page).
  • In Struts 1, Action classes extend the Action class.

Working

  • The client sends a request.
  • The Struts controller maps the request to the appropriate Action class.
  • The Action class executes the required business logic.
  • It interacts with the Model to process or retrieve data.
  • The Action class returns a result, and Struts forwards the request to the appropriate View.

7. What is the role of struts.xml?

struts.xml is the main configuration file in Struts 2. It defines how client requests are mapped to Action classes and specifies the results, interceptors, namespaces, and other framework settings.

  • Maps URL requests to the appropriate Action classes.
  • Defines Result pages (JSP, redirect, chain, etc.).
  • Configures Interceptors and Interceptor Stacks.
  • Supports Namespaces for organizing actions.

8. What is an Action Mapping?

Action Mapping is a configuration that maps an incoming client request (URL) to the appropriate Action class. It also defines the results (views) to be displayed after the Action class executes.

  • Specifies the result page (JSP, redirect, chain, etc.).
  • Configured in the struts.xml file in Struts 2.

Working

  • The client sends a request.
  • Struts checks the Action Mapping in struts.xml.
  • The request is mapped to the corresponding Action class.
  • The Action executes the required business logic.
  • Based on the returned result, Struts forwards the request to the configured view.

9. What is OGNL (Object Graph Navigation Language)?

OGNL (Object Graph Navigation Language) is an expression language used in Struts 2 to access and manipulate data stored in the Value Stack. It allows JSP pages, tags, and framework components to read and update Action class properties without writing Java code.

  • Reads and updates Action class properties.
  • Supports nested object navigation and method invocation.
  • Used extensively in Struts tags and JSP pages.

10. How is request processing handled in Struts?

In Struts, every client request passes through a front controller, which identifies the appropriate Action class, executes business logic, and returns the response to the user.

Request Processing Steps

  • Client sends an HTTP request.
  • The Front Controller receives the request.
  • Configuration file (struts.xml or struts-config.xml) identifies the corresponding Action.
  • Interceptors execute (Struts 2).
  • The Action class processes the request.
  • Business logic or service layer is invoked.
  • The Action returns a logical result.
  • The framework forwards the request to the appropriate JSP or other result type.
  • The response is sent back to the client.

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

12. What is the Value Stack?

The Value Stack is a central data storage mechanism in Struts 2 that stores the Action object and other application data during request processing. It allows JSP pages, Struts tags, and OGNL expressions to access and manipulate data without directly interacting with the Action class.

  • Automatically makes Action class data available to the View.
  • Works with Struts tags such as <s:property>, <s:textfield>, and <s:iterator>.
  • Created for every request and destroyed after the response is sent.

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

In a Struts-based application, every client request passes through the Controller, which identifies the appropriate Action class, executes the required business logic, and forwards the response to the correct View. This request-processing flow follows the MVC (Model-View-Controller) architecture.

Request Flow

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

Struts Interview Questions for Intermediate

14. What is the Lifecycle of a Struts Request?

The Struts request lifecycle describes how an HTTP request is processed from the moment it is sent by the client until the response is returned. Struts uses a Front Controller to receive all requests, process them through configuration and interceptors, invoke the appropriate Action class, and finally return the result to the user.

  • Interceptors perform pre- and post-processing.
  • Action executes the business logic.
  • Result is returned and rendered to the client.

Working Steps

  • Client sends an HTTP request.
  • The Front Controller receives the request.
  • Struts reads the configuration (struts.xml).
  • Interceptors execute before the Action.
  • The corresponding Action class is invoked.
  • Business logic is executed.
  • Action returns a logical result.
  • The appropriate view (JSP, redirect, etc.) is rendered.

Advantages

  • Centralized request processing.
  • Better separation of concerns.
  • Easy request management and maintenance.
  • Supports reusable interceptors.

15. Differentiate between Struts 1 and Struts 2.

Struts 1 and Struts 2 are two versions of the Apache Struts framework. Struts 2 is a complete redesign that provides simpler configuration, better extensibility, and improved performance.

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.

16. How does Struts implement the MVC pattern?

Struts follows the Model-View-Controller (MVC) architecture by separating the application into three independent layers. This separation improves maintainability, scalability, and code reusability.

  • Model: Contains business logic and database operations.
  • View: JSP pages display data to the user.
  • Controller: Action classes and Front Controller process requests.

Working

  • User submits a request through the View (JSP).
  • The Front Controller receives the request.
  • Controller forwards the request to the appropriate Action.
  • Action invokes the Model (Service/DAO).
  • Model processes the request and returns data.
  • Action selects the appropriate Result.
  • View displays the response to the user.

17. Difference Between Forward Action and Redirect Action

Forward and Redirect are two ways of transferring control after processing a request. Forward happens internally on the server, while Redirect instructs the browser to send a new request.

FeatureForwardRedirect
RequestSame requestNew request
URLDoes not changeChanges
SpeedFasterSlightly slower
Request AttributesPreservedLost
Browser InvolvementNoYes

18. What are Interceptor Stacks?

An Interceptor Stack is a predefined or custom collection of multiple interceptors that execute in a specific order before and after an Action is invoked. Instead of configuring each interceptor separately, a stack allows them to be applied together.

  • Can be predefined or custom.
  • Reusable across multiple Actions.
  • Common stack: defaultStack.

Advantages

  • Promotes code reuse.
  • Reduces configuration effort.
  • Keeps Action classes clean.
  • Supports modular request processing.

19. How do Interceptors work in Struts 2?

Interceptors in Struts 2 are reusable components that execute before and after an Action method. They provide common functionalities such as validation, authentication, logging, file upload, and exception handling without adding code to the Action class.

  • Configured in struts.xml.
  • Can be used individually or as part of an Interceptor Stack.
  • The defaultStack contains commonly used interceptors.

Working Steps

  • Client sends a request.
  • Front Controller receives the request.
  • Configured interceptors execute before the Action.
  • The Action method is invoked.
  • Interceptors execute after the Action (if applicable).
  • The Result is returned to the client.

20. What is the difference between ActionSupport and Action classes?

Action is an interface that defines the basic contract for an Action class, whereas ActionSupport is a convenience class that implements the Action interface and provides additional built-in features like validation, internationalization, and error handling.

FeatureAction InterfaceActionSupport Class
TypeInterfaceConcrete Class
ImplementationMust implement all methodsProvides default implementations
Validation SupportNoYes
Internationalization (i18n)NoYes
Error HandlingNoYes
RecommendedBasic useMost commonly used

21. What is Input Validation in Struts?

Input Validation is the process of verifying user input before it is processed by the application. It ensures that only valid and expected data is accepted, preventing invalid input and improving application security.

  • Improves application security.
  • Supports both client-side and server-side validation.
  • Can be configured using XML or annotations.

Benifits

  • Prevents invalid data entry.
  • Improves data integrity.
  • Enhances user experience.
  • Reduces server-side errors.

22. How is server-side validation implemented in Struts?

Server-side validation is performed on the server after a request is submitted. In Struts 2, it can be implemented using the validate() method, XML validation files, or validation annotations.

  • More secure than client-side validation.
  • Supports XML, annotations, and validate() method.
  • Prevents invalid data from reaching business logic.

Working

  • User submits the form.
  • Request reaches the server.
  • Struts executes validation rules.
  • If validation fails, error messages are returned to the View.
  • If validation succeeds, the Action method is executed.

23. What is Client-side Validation in Struts?

Client-side validation checks user input in the browser before the request is sent to the server. It provides immediate feedback to users, reducing unnecessary server requests and improving the user experience.

  • Reduces unnecessary server requests.
  • Usually implemented using JavaScript.
  • Improves user experience.

Working

  • User enters data in a form.
  • Validation rules are executed in the browser.
  • If input is invalid, error messages are displayed immediately.
  • If input is valid, the form is submitted to the server.
  • Server performs additional server-side validation.

24. What is Dynamic Method Invocation (DMI)?

Dynamic Method Invocation (DMI) is a feature in Struts 2 that allows different methods of the same Action class to be invoked through the request URL without creating separate Action mappings.

  • Uses the ! operator in the URL.
  • Reduces the need for multiple Action mappings.
  • Disabled by default in newer Struts versions for security.

Advantages

  • Reduces configuration.
  • Reuses the same Action class.
  • Simplifies Action management.

25. What are Result Types in Struts 2?

Result Types in Struts 2 determine how the framework responds after an Action method is executed. Based on the returned result, Struts can forward to a JSP, redirect to another Action or URL, return a stream, or generate other types of responses.

  • Configured in struts.xml.
  • Multiple Result Types are available for different scenarios.
  • The default Result Type is dispatcher.

Common Result Types

  • dispatcher: Forwards request to a JSP (default).
  • redirect: Redirects to another URL.
  • redirectAction: Redirects to another Action.
  • chain: Invokes another Action.
  • stream: Sends binary data such as files.
  • httpheader: Returns custom HTTP headers.

Working

  • Client sends a request.
  • Action class executes.
  • Action returns a logical result (e.g., "success").
  • Struts maps the result to a configured Result Type.
  • The corresponding view or response is returned.

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

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

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

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

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

Struts Interview Questions for Experienced

31. Explain the complete request flow in Struts 2.

The request flow in Struts 2 follows the MVC (Model-View-Controller) architecture. When a client sends a request, it is intercepted by the StrutsPrepareAndExecuteFilter, which prepares the request and forwards it to the appropriate Action class. The Action processes the business logic, and the framework returns the configured result (such as a JSP page or JSON response).

Working

  • The client sends an HTTP request.
  • StrutsPrepareAndExecuteFilter intercepts the request.
  • The filter loads the configuration from struts.xml.
  • The request URL is mapped to the appropriate Action.
  • Interceptors execute (validation, parameters, file upload, etc.).
  • The Action class executes business logic.
  • The Action returns a result name (success, error, etc.).
  • Struts maps the result name to the configured view.
  • The response is sent back to the client.

32. How does the Value Stack work internally?

The Value Stack is the central data storage mechanism in Struts 2. It stores the Action object, model objects, and other framework objects. Whenever a JSP page accesses a property using Struts tags or OGNL, Struts searches the Value Stack from top to bottom to find the required value.

Working Steps

  • A request reaches the Action.
  • Struts creates a Value Stack.
  • The Action object is pushed onto the stack.
  • Model objects may also be pushed onto the stack.
  • OGNL expressions search the stack for requested properties.
  • The matching value is returned to the view.

Advantages

  • Automatic data sharing between Action and View.
  • Eliminates manual request attribute handling.
  • Supports nested objects.
  • Simplifies data binding.

33. How does OGNL evaluate expressions?

OGNL (Object Graph Navigation Language) is the expression language used by Struts 2 to access and manipulate data stored in the Value Stack. It evaluates expressions by searching the Value Stack from top to bottom and retrieves the required property, method, or collection value automatically.

Working Steps

  • A request is processed, and Struts creates a Value Stack.
  • The Action object and other required objects are pushed onto the Value Stack.
  • A JSP page or Struts tag contains an OGNL expression (for example, %{user.name}).
  • The OGNL engine searches the Value Stack from top to bottom.
  • It locates the required object and evaluates the requested property or method.
  • The evaluated value is returned and displayed in the view.

34. What is the difference between Value Stack and Action Context?

Both Value Stack and Action Context store request-related information, but they serve different purposes.

FeatureValue StackAction Context
PurposeStores Action and model dataStores request execution data
AccessThrough OGNLThrough Java API
Used ByJSP tags and OGNLActions and Interceptors
ContainsAction, Model ObjectsRequest, Session, Application, Parameters
ScopeView dataRequest execution context

35. How do custom Interceptors work?

A Custom Interceptor allows developers to execute custom logic before or after an Action executes. It is useful for authentication, authorization, logging, auditing, and request preprocessing.

Working Steps

  • Create a class extending AbstractInterceptor.
  • Override the intercept() method.
  • Write custom logic before or after the Action.
  • Call invocation.invoke() to execute the Action.
  • Register the interceptor in struts.xml.
  • Apply it to an Action or Interceptor Stack.

Advantages

  • Promotes code reuse.
  • Centralizes common functionality.
  • Keeps Action classes clean.
  • Easy to plug into existing applications.

36. How do you create a custom Result Type?

A Custom Result Type allows developers to define how the response should be generated when the built-in result types are not sufficient.

Working Steps

  • Create a class implementing the Result interface.
  • Implement the execute() method.
  • Add custom response logic.
  • Register the result type in struts.xml.
  • Use it in Action result mappings.

37. How do you integrate Struts with Spring Framework?

Struts integrates with Spring Framework to use Spring's Dependency Injection (DI) and bean management features. Spring manages service and DAO objects, while Struts handles web requests.

Working Steps

  • Add Struts and Spring integration libraries.
  • Configure Spring beans in the Spring configuration file.
  • Configure the Struts Spring plugin.
  • Inject Spring-managed beans into Action classes.
  • Use the services inside Actions.

Advantages

  • Improves maintainability.
  • Simplifies testing.
  • Better separation of concerns.

38. How do you integrate Struts with Hibernate?

Struts integrates with Hibernate by using Hibernate in the service or DAO layer. The Action class calls service methods, which use Hibernate Sessions to perform database operations.

Working

  • Configure Hibernate.
  • Create entity classes.
  • Create DAO classes using Hibernate.
  • Create a service layer.
  • Inject the service into Struts Actions.
  • Execute CRUD operations through Hibernate.

39. How do you secure Struts applications against common vulnerabilities?

Struts applications should implement multiple security practices to protect against common attacks such as SQL Injection, Cross-Site Scripting (XSS), Cross-Site Request Forgery (CSRF), and Remote Code Execution (RCE).

Best Practices

  • Use the latest stable Struts version.
  • Enable CSRF protection.
  • Validate all user inputs.
  • Escape HTML output to prevent XSS.
  • Use parameterized queries or Hibernate.
  • Restrict OGNL expression execution.
  • Configure proper authentication and authorization.
  • Disable unnecessary Dynamic Method Invocation (DMI).
  • Keep third-party libraries updated.

Advantages

  • Protects sensitive data.
  • Prevents common web attacks.
  • Improves application reliability.

40. What is the difference between Value Stack and Action Context?

Both Value Stack and Action Context are important components in Struts 2, but they serve different purposes. Value Stack stores the Action object and model data that are accessed by the view (JSP), while Action Context stores request-related information such as request, session, application scope, parameters, and locale during request processing.

FeatureValue StackAction Context
PurposeStores Action objects and model dataStores request execution context and environment data
Main UseProvides data to the View (JSP)Provides request, session, application, and parameter information
Access MethodAccessed using OGNL expressions and Struts tagsAccessed using the ActionContext class
ContainsAction object, model objects, temporary valuesRequest, Session, Application, Parameters, Locale, Value Stack
Used ByJSP pages and Struts tagsActions, Interceptors, and framework components
LifetimeExists during request processingExists during request processing
RelationshipData is retrieved from the Value StackHolds the Value Stack along with other contextual information
Comment

Explore