Struts Interview Questions and Answers

Last updated on Feb 02, 2022
  • Share
Struts Interview Questions

Most Frequently Asked Struts Interview Questions

Here in this article, we will be listing frequently asked Struts Interview Questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q1. What is Struts? Explain

Struts is a free, MVC-based, open-source framework that helps developers create modern Java applications. This framework prefers convention over configuration and is extensible through a plugin architecture.

Struts was initially built by Craig McClanahan. The first stable version was released in June 2001. Struts 2.0 was released in 2014.

Q2. Explain the components of Struts?

Following are the key components of Struts:

  • JSP Programs or View Layer Resources
  • FormBean Class Java Class or Controller Layer Resources
  • Action Servlet Built-in Controller Servlet or Controller Layer Resources
  • Action Class Java Class or Controller Layer Resources
  • web.xml Deployment Descriptor file of the web application
  • Struts Configuration File XML File or Controller Layer Resources
Q3. What is the difference between struts and spring? Explain
Answer Spring MVC Struts
1. Noninvasive Invasive
2. Loosely coupled Tightly Coupled
3. Layered architecture Not layered architecture
Q4. What is the differences between Struts1 and Struts2?
Answer Struts 1 Struts 2
1. Form beans define properties, setters and getters Getters and Setters are defined in action classes
2. Execute() method exposes servlet API for testing Dependency Injection simplifies the testing process
3. Multiple tag libraries The single library includes all tags
4. RequestProcessor class present Interceptors present
Q5. How we can Install Struts?

Installation process can be divided in four steps that's are given below:

  • Setup Java Development Kit
  • Setup Apache Tomcat
  • Setup Eclipse
  • Setup Struts2 Libraries
Q6. Explain the difference between DispatchAction and LookupDispatchAction in Struts?
Answer DispatchAction LookupDispatchAction
1. Parent class of LookupDispatchAction Subclass of Dispatch Action
2. More useful if not using Internalization function Useful when using Internalization
3. Not useful in I18N Useful in I18N
Q7. How we can controlled duplicate form submission in Struts?

Duplicate form submission can occur when you by refresh the page, press back button, or if there is a virus in your machine.

There are 2 ways to prevent duplicate requests:

  • Through isTokenValid() method
  • By managing clearing request object.
Q8. What do you mean by ActionServlet?

ActionServlet is like a "controller" in the MVC architecture for web apps which is known as Model 2. The requests to server pass through the controller, which is responsible for managing requests.

The usual flow in struts begins with the ActionServlet and call to process() method of RequestProcessor.

Q9. What do you mean by ActionForm?

An ActionForm is a JavaBean that is associated with ActionMappings and handles session state for the apps. The ActionForm object populates automatically on the server side when any set of data is entered on the client side.

If you are preparing for Struts interviews, you can read Struts interview questions and answers for freshers for clarity and insight.

Q10. What is validate() and reset() functions?

validate() is like a hook that can be overridden by different subclasses for performing validations on incoming data. This method gets called after a Form Bean gets populated with incoming data. This method includes return type ActionErrors.

Syntax is:

public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)

reset() is a method that gets overridden by subclasses. It is a hook that gets summoned before FormBean gets populated with request data from HTML. Using this method, all form fields get reset.

Syntax is:

public void reset() {}

Reviewed and verified by Best Interview Question
Best Interview Question

With our 10+ experience in PHP, MySQL, React, Python & more our technical consulting firm has received the privilege of working with top projects, 100 and still counting. Our team of 25+ is skilled in...