Code360 powered by Coding Ninjas X Code360 powered by Coding Ninjas X
Last Updated: Jun 12, 2024

Struts Interview Questions

Author Aditya kumar
0 upvote
Table of contents
Projects ideas to get shortlisted for data roles at MAANG
13 Jun, 2024 @ 01:30 PM
Muskan Rathore
Data Scientist @

There are several well-known Java frameworks that have helped develop numerous applications across various IT businesses. Struts is a framework that is among them.

Java open-source framework called Struts is created by Apache. It offers an implementation of the MVC architecture. It offers us ready-made MVC classes that we can use and extend. The framework also has a ready-to-use validation mechanism. Struts' model layer, which enables it to cooperate with other Java technologies like JDBC, EJB, Spring, Hibernate, and others, is its strongest point. The original Struts are rarely used by businesses. The vast majority of companies favor the second format. In the second iteration of the Struts, more functionalities are added.

Struts interview questions

Let's discuss the top Struts interview questions with their detailed solutions.

Easy Struts Interview Questions

Easy Struts Interview Questions

1. What do you mean by Struts?

Java Enterprise Edition Web applications may be created fast and easily using the open-source Struts Framework. Utilizing and extending the Java Servlet API, it promotes the model-view-controller (MVC) architecture.


2. What characteristics does Struts have?

  • Setting up MVC components
  • Action based on POJO
  • Support for AJAX
  • Different Tag Support Different Result Types
  • Integration Assistance


3. Describe interceptor.

Interceptor is a pluggable object invoked during a request's pre and post-processing.


4. What are the interceptor's life cycle methods?

  • public void init ()
  • public void intercept(ActionInvocation aIn)
  • public void destroy ()


5. Describe MVC.

A design pattern is MVC. MVC Stands for Model, View, and Controller. A controller serves as an interface between a model, which represents data, and a view, which provides a presentation.



6. Describe the various Struts framework elements.

The Struts framework is made up of the following elements:

  • FormBean Class (Controller Layer Resources)
  • JSP Programs (View Layer Resources)
  • Action Class
  • Action Servlet(Built-in Controller Servlet)
  • Struts Configuration File (XML File)
  • web.xml (Deployment Descriptor file of the web application)


7. What are the main Struts application classes?

The crucial classes for any application of Struts are listed below.

  • Action Servlet
  • Action Form
  • Action Class
  • Action Forward
  • Action Mapping


8. What should we do initially to use the Struts application?

We just need to add the Struts.jar file to our development environment to use the framework. We can use the framework and create Strut-based apps once the jar file is in the CLASSPATH.


9. What is the OGNL?

A Struts2 expression language is OGNL. OGNL stands for Object Graph Navigation Language.

Also see, Kotlin Interview Questions


10. Describe the execAndWait interceptor.

The execAndWait interceptor, also called ExecuteAndWait, is used to show interim or wait results.


Let us now discuss the medium type of Struts interview questions.

Medium Struts Interview Questions

Medium Struts Interview Questions

11. What advantages does the Struts framework offer?

Because Struts is built on MVC, there is a strong separation of the various layers, making the creation and modification of Struts applications simple. Struts applications are easily changeable thanks to the use of several configuration files. Struts is also open source and therefore inexpensive.


12. How does Struts 2 respond to the request?

  • The user first communicates with the server after receiving the request.
  • After that, FilterDispatcher manages the request and decides what to do with it.
  • The specified interceptors carry out pre-processing tasks, including file upload, error handling, etc.
  • The chosen action is now carried out, and the operation is finished.
  • Interceptors are used to carry out post-processing tasks like file upload, exception handling, etc.
  • The user gets shown the finished product in the form of a view page.


13. Name a few drawbacks of the Struts framework.

  • Nothing is documented.
  • It isn't entirely transparent.
  • Only one servlet controller is there.
  • There is so much to learn.
  • The approach is unwavering.


14. Why do we use ActionServlet?

In the Model 2 MVC architecture for online apps, ActionServlet functions similarly to a "controller." The controller, which is in charge of controlling requests, is where the requests to the server are sent.

The ActionServlet and the call to the RequestProcessor's process() method start the standard flow in struts.


15. What is ActionForm?

A JavaBean called an ActionForm manages the apps' session state and is connected to ActionMappings. Any time a data set is entered on the client side, the ActionForm object immediately populates itself on the server.


16. In Struts, what are OGNL and ValueStack mean?

ValueStack is a stack where all data and values associated with actions are saved, whereas OGNL is a library where the data or values in ValueStack are updated.


17. How should exceptions be handled in Struts2?

The mechanism for handling exceptions in Struts2 is extremely thorough. After packages have defined global outcomes, specific exceptions can be mapped to these result pages. Both the global package and action levels can do exception mapping.


18. Why is ActionServlet a singleton in Struts?

The Struts framework's ActionServlet controller handles all user requests. ActionServlet is based on the singleton design pattern since only one object needs to be constructed for this controller class. Many threads are created in response to each user request.

You can also check out Singleton Design Pattern C# here.


19. Describe how Struts 2's token interceptor works.

The most frequent problem with online applications is a double form submission, which causes the user to be charged twice and the database to store double values. We can use a token interceptor to stop multiple form submissions. This interceptor is defined in the struts-default package.


20. What does package struts-default stand for?

All of the Struts2 interceptors are defined in the struts-default package, along with the most popular interceptor stack. Extending this package while configuring our application package is advisable to avoid having to configure interceptors twice. This information is provided to developers to assist them in setting up interceptors and result pages for our application.


Let us now discuss the hard type of Struts interview questions.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job

Hard Struts Interview Questions

Hard Struts Interview Questions

21. Explain the differences between basic HTML tags and HTML tags specific to Struts.

The key distinctions between standard HTML tags and HTML tags specific to Strut are as follows:

  • HTML tags are static by nature, whereas HTML tags specific to Struts are dynamic.
  • While Struts coordinates HTML, it also has its own tag libraries.
  • The tags for struts, however, can be user-defined, unlike the tags for HTML.


22. What occurs when an HTTP request is sent from a client browser?

After a request is sent, the subsequent actions occur:

  • The ActionServlet receives the request.
  • The struts-config.xml file contains details about Actions, ActionForms, ActionMappings, and ActionForwards.
  • When the ActionServelet starts up, it reads the struts-config.xml file and creates a database of configuration objects. The ActionServlet later uses this object to make a decision when handling the request.


23. On a JSP form, how is client-side validation enabled?

Before enabling client-side validation in Struts, we must first enable the validator plug-in in the struts-config.xml file. The following configuration elements are added to this file:

<!--  ValidatorPlugin -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">


The validation.xml file then contains the rules for validating data. The following code is added to the validation.xml file if a form contains an email field and if we want to enable client-side validation for this field:

<form name="myTestForm">
<field  property="email"
<arg key=""/>


24. What does the action class' Execute method serve?

The action class's Execute method is in charge of carrying out business logic. This approach is used whenever processing the user's request is necessary. The ActionForward object returned by this method directs the program to the proper page.

The execute method will return an object of the type ActionForward with the name "exampleFunAction" defined in the struts-config.xml example below:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class actionFunExample extends Action
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{
return mapping.findForward("exampleFunAction");


Must Read Apache Server

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

The action-mapping element in the Struts configuration file (struts-config.xml) defines the forwarding options.

When a user clicks on the hyperlink in the example below, the request will be routed to /pages/testing.jsp using the following configurations from the struts-config.xml file:

<action  path="/test" forward="/pages/testing.jsp">

When a user clicks the following link on the JSP website, the following forwarding will happen:

<html:link</strong> page="/</strong>">Controller Example</html:link>


26. What is Struts' declarative exception handling?

Declarative exception handling in Struts is the process of defining exception handling logic either in the action tag or the struts-config.xml file.

The following example shows how to define the NullPointerException exception in the struts-config.xml file:


<exception key="test.key"





27. What makes Struts1 and Struts2 distinct from one another?

Struts 1Struts 2
ActionForms are a feature of Struts 1. These classes match the JSP forms. The Action classes utilize these ActionForms' data to fill Data Transfer Objects.No action forms are in use. No DTO is necessary because the JSP form translates straight to POJO classes. Because fewer classes are needed, less maintenance is required.
The language of expression is JSTL (Java Standard Tag Library).Additionally, employed as an expressive language, OGNL (Object Graphic Notation Language) is more potent than JSTL. JSTL can, however, also be utilized with struts 2.x.
It has several tag libraries.Numerous tags are present in a single library.
Action classes are limited in their ability to extend other classes since they must extend the abstract base class.The execute() method on a POJO class can be used to create more versatile Action classes. Action classes can also be created by extending the ActionSupport class or implementing the Action interface.
HttpServletRequest and HttpServletResponse parameters of type HttpServletRequest and HttpServletResponse are passed as arguments to action classes' execute function. Because of this, struts 1.x actions depend on the servlet API.The Action class in Struts 2 does not depend on a servlet because the execute() function does not accept any parameters. The request and answer are still accessible to Struts 2 Actions, though.


28. What separates field validators from plain validators?

  • Validators at the action level can use the plain-validators syntax. Here, many fields can all be validated by a single validator. The disadvantage of this method is that we can only utilize a limited number of validators on a single field.
  • Field-validator syntax applies to the field-level validator. In this situation, one field may use many validators. The disadvantage of this method, as opposed to plain-validator, is that only one validator can be used across several fields.


29. What do the validate() and reset() functions mean?

The validate() method performs validations on incoming data, which other subclasses can override. This function is called once an incoming Form Bean has been filled with data. This method includes a return type for ActionErrors.

public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {}

The reset() can be overridden by subclasses. It is a hook that is activated before the FormBean receives the HTML request data. This method resets all form fields.

public void reset() {}


30. Describe a few of the Struts2 annotations that are useful.

Important annotations included in Struts2 include

1. Creating an action class with @Action.

2. Using @Actions, you can set up a single class for numerous actions.

3. Utilizing @Namespace and @Namespaces to create various modules.

4. Result pages with @Result.

5. @ResultPath for setting the placement of result pages.


This article contains the Struts interview questions frequently asked in technical interviews. If you are intrigued by this article on Struts interview questions, check out our other blogs.

Check out the Coding Ninjas Website, Android DevelopmentCoding Ninjas Studio ProblemsCoding Ninjas Studio Interview BundleCoding Ninjas Studio Interview ExperiencesCoding Ninjas CoursesCoding Ninjas Studio Contests, and Coding Ninjas Studio Test Series for more excellent content. 

Happy Learning!

Previous article
Java Stream API Interview Questions and Answers
Next article
Spring Interview Questions and Answers (2024)