5 Interview Questions About Struts (With Sample Answers)

By Indeed Editorial Team

Published August 9, 2022

The Indeed Editorial Team comprises a diverse and talented team of writers, researchers and subject matter experts equipped with Indeed's data and insights to deliver useful tips to help guide your career journey.

Struts is an open-source software framework that developers use to create and customize web pages and applications. It can streamline their work because of the way it presents information and organizes workflow. If you're applying for a job where the use of Struts is integral, it's beneficial to prepare for skill-based technical questions during an interview. In this article, we discuss some questions an interview might ask and provide you with potential answers.

5 Struts interview questions

Here are five questions you may have to answer when interviewing for a software developer position:

1. What is Struts, and why do we use it?

This is often one of the first questions in the interview to help determine your basic familiarity with the software. Provide a quick overview of the software. Then, demonstrate your specific knowledge about its applications.

Example: Struts allows developers to build and create web pages. You can use Struts if you're creating a Java-based web page. The Struts package includes servlets, custom tags, message resources, Jakarta packages and JavaBeans.

Essentially, developers use Struts because it can make their work easier. Struts uses a Model, View and Controller architecture, which separates the business logic, design element and controller. In doing so, it helps simplify code and makes it much more manageable for developers.

Related: 20 Skills in Demand in Today's Workforce

2. What are the core classes of the Struts framework and their functions?

Interviewers ask this question to gauge your operational knowledge of the primary features of Struts. The first portion of the question is informational, so list all the classes you can recall. Then, show your in-depth knowledge by succinctly describing each class's role in the framework.

Example: The core classes within the Struts framework are Action Class, ActionForm Class, ActionMappling Class, ActionForward Class and ActionServlet Class. Overall, the classes use business logic to handle HTTP requests. Then, the request processor decides on the correct action to resolve the request and executes it.

Action Servlet is effectively the most important part of Struts because it provides the framework for the application to operate. Action Class handles all incoming requests, and it performs the action that completes the request. Action Forward is the action that takes the initial request and forwards it along to the proper destination for resolution. Action Mapping provides the path between the object or request and the action. Action Form is a JavaBean, and it refers to all forms used within the application.

Related: The Best Job Skills To Make Your Resume Stand Out

3. Under what circumstances do you use a Struts framework?

This technical question helps interviewers understand whether you can determine the right scenarios for using Struts. While your answer should cover the technical aspects, you can also use this moment to discuss the value of Struts and the benefits of using it.

Example: Generally, developers use Struts to create web applications. You can use the framework during application development that requires a significant amount of enterprise software and programming. Struts is also useful when there is an application that you plan to reuse, particularly when the application is completely configurable. Finally, developers can use Struts when managing a loosely configured application with different, segregated layers.

Struts is an incredibly effective programming tool. Because it uses the Model View Controller framework, it's particularly useful when you're building applications with the Java 2 Platform or the Enterprise Edition. If you use the Struts composite view, you can manage the layout of the subviews, implement a template and easily customize the application.

Related: How To Become a Full-Stack Java Developer in 5 Steps

4. Why do duplicate forms sometimes exist in Struts, and how can you correct this issue?

Interviewers may want to determine how you handle a common issue that can occur when using Struts, which is the possible duplication of forms. Your response can show that you understand the problem and why it matters. Then you can explain your process for addressing this challenge.

Example: A duplicate form can occur under several scenarios. For example, if you hit the refresh button, that action could cause duplication. Other potential instances of duplication are when you attempt to use the "back" button, access the history feature on a browser or attempt to submit a form they already submitted. While a duplicate form might not cause any issues in all cases, it can create problems depending on the application. For example, if duplicated, an application involving payment could create duplicate charges.**

Struts offers a couple methods to prevent the creation of duplicate forms. The saveToken() option creates a unique token that sticks with the form submission throughout a user's session. The other option for preventing duplications is the isTokenValid () method. This method checks the uniqueness of tokens to avoid creating multiple copies.

Related: How To Become a Java Architect: Skills and Requirements

5. What is a SwitchAction and ForwardAction in Struts?

Interviewers often want to determine whether you understand these two actions within the Struts framework. Your answer can further demonstrate your knowledge of the Struts and whether you understand the nuances of how it operates. A good way to answer the question might be to define each action briefly and then discuss how they differ within Struts.

Example: SwitchAction and ForwardAction can both direct a request to the appropriate application that can complete it. However, they perform very different functions. SwitchAction actually changes the action between modules by forwarding the uniform resource identifier, or URI, control to a different module. With SwitchAction, there are two parameters that affect the module change: page and prefix. The prefix specifies the new module gaining control, while the page parameter is what transfers control after the switch.

ForwardAction occurs when Struts forwards a request to a specific URI. Essentially, the ForwardAction exists as the destination. ForwardAction replaces the Java specification code through the application. The application actually defines the forward action through the configuration file.

Explore more articles