Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Before you go!

Take this "Struts Interview Questions" interview guide with you

Welcome to Interviewbit, help us create the best experience for you!

Currently, You are a:

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your career...

Current Company *
Enter company name *
Experience *

You're all set!

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

Struts Interview Questions Last updated on May 31, 2022

Download PDF


Your requested download is ready!
Click here to download.

There are several popular frameworks of Java that have contributed to various applications in different IT industries. One of these frameworks is the Struts framework.

Apache's Struts framework is a Java open-source framework. It provides an MVC architectural implementation. It provides us with pre-built MVC classes that we can utilize and extend. The framework also includes a validation mechanism that is ready to use. Struts' strength resides in its model layer, which allows it to work with other Java technologies such as JDBC, EJB, Spring, Hibernate, and others. Companies rarely employ the first version of struts. The second form is preferred by the majority of businesses. Additional features are included in the second version of the struts.

Struts have their own custom tag libraries. If you are not a Java developer, you can not implement Struts applications. To make you aware of various aspects of struts, this article will help you gain knowledge on struts with this exhaustive list of the most commonly asked struts 2 interview questions.

Crack your next tech interview with confidence!
Take a free mock interview, get instant⚡️ feedback and recommendation💡

Struts Interview Questions for Freshers

1. What is Struts?

The Struts Framework is an open-source Web application framework for quickly and easily developing Java Enterprise Edition Web applications. It promotes the model-view-controller (MVC) architecture by utilising and extending the Java Servlet API.

The goal of the Struts Framework was to separate the "model," which is the application logic that communicates with the database, from the "view," which is the HTML pages presented to the client/user, and from the "controller," which is the instance that passes data between the model and the client's view.

2. Describe various components of the Struts framework.

The following are the components of the struts framework:

  • JSP Programs (View Layer Resources): The presentation logic of a JSP program is used to create a user interface for end-users and to prepare the model layer's results.
  • FormBean Class (Controller Layer Resources): A form bean is a Java bean type. It is a subclass of the ActionForm class that contains HTML form data from a submitted client request or can store input data from a user-clicked Struts action link.
  • Action Servlet(Built-in Controller Servlet): Every Struts application comes with a built-in Controller Servlet. This servlet program's integration logic will be dynamically constructed depending on the rules and guidelines specified in the Struts configuration file. This integration logic determines and regulates the execution flow in struts applications.
  • Action Class: It's a Java extension of org.apache.struts.action. This is an action class. It has the functionality to interface with other model layer resources; therefore it can act as a model layer resource.
  • web.xml (Deployment Descriptor file of the web application): Because the web.xml web application descriptor file is at the heart of any Java online application, it's only natural that it's also at the heart of the Struts framework. Struts specify its FilterDispatcher, a Servlet Filter class that initializes the Struts framework and handles all requests, in the web.xml file.
  • Struts Configuration File (XML File): The struts-config.xml configuration file serves as a connector between the Web application's View and Model components.

3. What are the key classes of a Struts application?

Following are the important classes for any struts application.

  • Action Servlet: It is the controller class which is in charge of all requests that come in.
  • Action Class: All business logic, often known as a Model, is constructed using the Action class.
  • Action Form: It is a Java bean that connects one or more Action Mappings. It keeps a web application's session state safe.
  • Action Mapping: We can do the mapping between Object and Action using it.
  • Action Forward: It's utilised to send the Controller's result to the target.
You can download a PDF version of Struts Interview Questions.

Download PDF


Your requested download is ready!
Click here to download.

4. What is MVC architecture in the Struts framework?

MVC stands for Model View Controller. Here is a brief description of the same.

  • To store, retrieve, and manipulate data, the model contains the business logic and interacts with the persistence storage.
  • The view is in charge of returning the results to the user. JSP is used to implement the view layer in Struts.
  • The controller handles all of the user's requests and returns the relevant view. The ActionServlet performs the controller's function in Struts.

5. What is an interceptor? Also, mention its lifecycle methods.

During the preprocessing and postprocessing of a request, an object is invoked known as an interceptor. Validation, exception handling, internationalization, showing interim results, and other actions are performed by the interceptor in Struts 2.

An interceptor's lifecycle methods are as follows:

  • init public void ():  It is only called once and is used to set up the interceptor.
  • public string intercept (ActionInvocation ai):  It is used to specify the request processing logic and is called for each request. The result page will be invoked if it returns a string; otherwise, the next interceptor or action will be invoked if it returns the invoke() function of the ActionInvocation interface.
  • public void destroy():  It can only be used once to destroy the interceptor.

6. What is execAndWait interceptor?

For long-running action classes, Struts2 introduces the execAndWait interceptor. We can use this interceptor to provide the client with an interim response page, and once the processing is complete, the client will receive the final response. The ExecuteAndWaitInterceptor class implements this interceptor, which is described in the struts-default package.

7. What is the first step to start using the struts application?

To use the framework, we only need to include the struts.jar file in our development environment. After the jar file is in the CLASSPATH, we may use the framework and build Strut-based apps.

8. What is the difference between Struts and Struts2?

Struts Struts 2
In Struts 1, ActionForms are used. These classes correspond to JSP forms. The data in these ActonForms is used by the Action classes to populate Data Transfer Objects. There are no action forms in use. The JSP form maps directly to POJO classes; thus no DTO is required. As a result, the number of classes is reduced, resulting in less maintenance.
The expression language is JSTL (Java Standard Tag Library). OGNL (Object Graphic Notation Language) is also used as an expressive language, and it is more powerful than JSTL. However, JSTL may also be used with struts 2.x.
It has multiple tag libraries The single library includes multiple tags.
Because action classes must extend the abstract base class, they cannot extend any other classes. Action classes are more flexible, and they can be constructed by implementing the Action interface, extending the ActionSupport class, or simply calling the execute() method on a POJO class.
The HttpServletRequest and HttpServletResponse parameters in the execute method of action classes are of type HttpServletRequest and HttpServletResponse. As a result, struts 1.x actions are reliant on the servlet API. Because the execute() function does not accept any parameters, the Action class in struts 2 does not have a servlet dependency. However, Struts 2 Actions can still access the request and response if necessary.

9. What is ForwardAction in Struts?

ForwardAction is applied when combining an existing application with struts. ForwardAction is also used for transferring total control from one location to another, such as from a JSP to a local server. When the benefits of struts functionality are desired after the integration with Struts, ForwardAction is employed.

10. How many servlet controllers does Struts application use?

The Struts framework uses a centralised control model, with a single servlet controller controlling the entire application. As a result, a servlet application only needs one servlet controller.

11. How can validation errors be displayed on a JSP page?

When a user submits a form with an improper data format, a validation error occurs. To validate this data, Struts provides the Validator() method, which allows the developer or programmer to validate data from both the client and server sides. This syntax can be used to display errors on the JSP page: <html:error/>

12. How struts 2 handle the request?

  • The user first sends the received request to the server.
  • The request is then handled by FilterDispatcher, which chooses the best action for it.
  • Pre-processing actions such as file upload, error handling, and so on are performed by the designated interceptors.
  • The selected action is now carried out, and the operation is completed.
  • Interceptors are used to execute post-processing actions such as file upload, exception handling, and so on.
  • The user is presented with the final result in the form of a view page.

13. What is ActionForm in Struts?

An ActionForm is a JavaBean that is linked to ActionMappings and manages the apps' session state. When any set of data is entered on the client-side, the ActionForm object populates automatically on the server-side.

14. What is the struts-default package?

The struts-default package defines all of the Struts2 interceptors, as well as the most often used interceptor stack. To prevent having to configure interceptors twice, it's best to extend this package while configuring our application package. This is given to aid developers in the configuration of interceptors and result pages in our application.

15. Describe the functionality of the token interceptor in Struts 2.

The most common issue with web applications is a double form submission, which results in the user being charged twice and the database retaining double values. To solve the problem of double form submission, we can use a token interceptor. The struts-default package defines this interceptor.

16. What are tiles in the Struts application?

Tiles are a type of presentation component that can be reused. Create a basic layout with several sections before using Tiles. Then, in an external configuration file, define a JSP page that should occupy the correct sections.

17. List some of the disadvantages of the Struts framework.

  • There is no documentation.
  • Transparency isn't complete.
  • There is only one servlet controller.
  • There is a great deal to learn.
  • The strategy is unyielding.

18. What is DynaActionForm?

DynaActionForm is a subclass of the ActionForm class that is used to dynamically create form beans. In order to generate a bean form, configuration files are used.

19. What are ActionServlets?

ActionServlet is equal to "controller" in the MVC architecture for web apps. Requests to the server are routed to the controller, which is in charge of request management. The typical struts flow starts with the ActionServlet and a call to the RequestProcessor's process() method.

20. Why is ActionServlet singleton in Struts?

ActionServlet is a controller in the Struts framework, and it manages all user requests. Because only one object needs to be produced for this controller class, ActionServlet is built on a singleton design pattern. For each user request, many threads are formed subsequently.

Struts Interview Questions for Experienced

21. When to use SwitchAction class?

When we have a modular application with various modules working independently, the optimum situation for using the SwitchAction class is. We can transition from a resource in one module to another resource in a separate module of the application using the SwitchAction class.

22. How to handle exceptions in Struts2?

Struts2 has a highly comprehensive framework for handling exceptions. Packages can define global outcomes, and then specific exceptions can be mapped to these result pages. Exception mapping can be performed at both the global package and action levels.

23. What are OGNL and ValueStack in Struts?

ValueStack is a stack where all values and data linked to actions are saved, whereas OGNL is a library through which the ValueStack data or values are changed.

24. State the difference between simple HTML tags and struts-specific HTML tags.

The following are the main differences between HTML tags and Strut-specific HTML tags:

  • HTML tags are static by nature, while Struts-specific HTML tags are dynamic.
  • Although HTML is coordinated in Struts, Struts has its own tag libraries.
  • The tags for HTML, on the other hand, cannot be user-defined, whereas the tags for struts can.

25. What is the Resource bundle properties document?

The resource bundle properties document is used to define customised error messages in key-value pairs for any code faults that might arise. This method helps to keep the code clean by removing the need for the developer to avoid all error messages within the function.

26. What happens when a client browser issues an HTTP request?

The following steps occur after a request is sent:

  • The request is received by the ActionServlet.
  • Details on Actions, ActionForms, ActionMappings, and ActionForwards can be found in the struts-config.xml file.
  • The ActionServelet reads the struts-config.xml file and builds a database of configuration objects when it starts up. Later, when processing the request, the ActionServlet refers to this object to make a decision.

27. Which file does the controller use to get request routing mapping information?

The controller gets all mapping information from a configuration file called "struts-config.xml" before deciding which action to employ for routing the user's request. It acts as a network router, processing and mapping requests to the appropriate action or resource.

28. What is an interceptor stack?

An interceptor stack allows us to aggregate many interceptors into a package for later usage. BasicStack and defaultStack are two of the most commonly used interceptor stacks created by the struts-default package. At the beginning of the package, we can establish our own interceptor stack and then configure our action classes to use it.

29. What is the difference between field and plain validators?

  • Action level validators can utilise the plain-validators syntax. In this instance, a single validator can be used to validate many fields. However, the drawback of this technique is that we can't use many validators on a single field.
  • The field-level validator can use the field-validator syntax. Multiple validators can be applied to a single field in this case. However, unlike plain-validator, this technique has the drawback of not being able to apply a single validator to several fields.

30. What is meant by the validate() and reset() function?

validate() is used for conducting validations on incoming data that can be overridden by different subclasses. After a Form Bean has been filled with incoming data, this function is invoked. The ActionErrors return type is included in this method.

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

Subclasses have the ability to override reset(). It's a hook that gets called before FormBean is filled with HTML request data. All form fields are reset using this way.

public void reset() {}

Conclusion

In this blog, we have listed a good number of common struts interview questions. It also covered the enhanced part of struts i.e struts 2 that would help you gain interest in how this framework is useful in creating good applications and widely used by IT professionals for their applications. Hope this pool of questions will help you in cracking your interview,

Useful Learning Resources

Happy Learning!

Struts Framework MCQ

1.

Which checks the given string against the specified regular expression and can be used as a password, security key, and so on?

2.

Which strut class is in charge of converting Strings to data types?

3.

Which is used to make an asynchronous request, i.e. one that does not block the user and transmits only the required field data to the server-side, rather than all of it, resulting in a rapid response?

4.

What is the purpose of the annotation @Validations?

5.

Which of these is combined into a single Framework by Struts?

6.

The controller's dispatch to the action class is based on a configuration provided by?

7.

What does the @TypeConversion Annotation do?

8.

Which of the following tags is used to indicate a form-bean of a dynamic validation form?

9.

To make the creation of struts 2 applications easier, which technology supports numerous types of tags such as UI tags, data tags, control tags, and so on?

10.

To save information in the session scope, the Action class must implement which interface?

Get Placed at Top Product Companies with Scaler Know More 
Get Placed at Top Product Companies with Scaler Know More 
Get Placed at Top Product Companies with Scaler
Sat transparent 640a34d454880bf68e3bfdf33f2389f2214043f59ad18b4c7f7b114e834fb257.svg

Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Personalised feedback report with solutions
Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Real life Interview Questions
Point markers b3add1cc88e4996b2df6e0aedb9f0d1b65fa73c51b7ada8fbee3895a2aa11802.svg Identify exact topics to improve

Your feedback is important to help us improve.
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
Select an option *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
Graduation Year *
Graduation Year *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test