Struts interview questions and answers for Java web developers
Struts interview questions check whether you can work safely inside an Apache Struts application, which today usually means maintaining or migrating one. Expect questions on how Struts 2 handles a request through its filter, interceptors, action and result, how the value stack and OGNL bind data, how validation and type conversion work, how Struts 1 differs, and how you would keep an older application patched or move it to Spring.
By Evin JohnPublished 7 min read
Why Struts still appears in interviews
Few teams start new projects on Struts, but many banks, insurers, governments and enterprise software vendors still run large Struts applications. That is where the interviews come from: maintenance roles, modernization projects and Java developer jobs where a legacy module sits beside newer Spring code. Interviewers want three things. You understand the framework well enough to change it without breaking it, you take its security history seriously, and you have a sensible view on migration. For the servlet and container layer underneath, see J2EE interview questions.
- Java and web basicsServlets, filters, sessions and the MVC pattern, since Struts sits on top of them.
- Framework roundRequest flow, configuration, actions, interceptors, results, validation and tags.
- Code readingA struts.xml file or an action class with a bug, such as an unvalidated parameter or shared state.
- Modernization talkHow you would upgrade, secure or migrate a large Struts application without a risky rewrite.
Fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is Struts and which pattern does it implement? | Overview | An open-source Java web framework from the Apache Software Foundation that implements MVC: actions as controllers, models in Java objects, and views in JSP or templates. |
| How do Struts 1 and Struts 2 differ? | History | Struts 2 grew out of WebWork rather than Struts 1. It uses a filter instead of ActionServlet, plain classes as actions instead of subclasses with ActionForms, interceptors, the value stack and OGNL. Struts 1 has been end-of-life for years. |
| What does the Struts 2 filter do? | Entry point | The prepare-and-execute filter declared in web.xml intercepts requests, finds the matching action mapping, builds the action invocation and runs it. |
| What does struts.xml contain? | Configuration | Packages, action mappings from names to classes and methods, results for each outcome, interceptor stacks and constants. Annotations or the Convention plugin can replace much of it. |
| What is an action in Struts 2? | Controller | A class with a method that returns a result name such as success or input. Extending ActionSupport adds validation, messages and i18n helpers but is optional. |
| What is a result? | Response | What happens after the action returns, mapped by name: dispatch to a JSP, redirect, redirect to another action, stream a file or return JSON through a plugin. |
| What is an interceptor? | Cross-cutting logic | A component that runs before and after the action, used for parameter binding, file upload, validation, logging, security checks and more. Interceptors run as a stack. |
| What is the value stack? | Data binding | A stack of objects for the current request, with the action on top. Tags and OGNL expressions read from it and the params interceptor writes request parameters into it. |
| What is OGNL? | Expressions | Object-Graph Navigation Language, used to get and set properties on the value stack from tags and parameter names. |
| What are Struts tags? | Views | A tag library (such as s:form, s:textfield and s:property) that renders forms and values from the value stack, with themes that control generated markup. |
Intermediate: actions, interceptors and validation
- Are Struts actions thread-safe? In Struts 2 a new action is created for each request, so instance fields are safe. In Struts 1 one action instance serves all requests, so instance fields leak data between users; keep state in local variables or the form bean.
- What is in the default interceptor stack, roughly? Exception handling, servlet objects, internationalization, prepare, model-driven, file upload, checkbox handling, static and request parameters, conversion errors, validation and workflow. Order matters: validation must run after parameters are set.
- How does validation work? Declarative rules in an XML file named after the action or in annotations, plus an optional validate() method. If there are errors, the workflow interceptor stops the action and returns the input result.
- What do ModelDriven and Preparable do? ModelDriven pushes a model object onto the value stack so form fields bind to it directly. Preparable runs a prepare() method before parameters bind, often to load an entity from the database.
- How do you stop double form submission? The token interceptor with a token tag in the form, which rejects a second post with the same token, or the token-session variant that replays the first result.
- How do you write a custom interceptor? Implement the Interceptor interface or extend AbstractInterceptor, do work before and after
invocation.invoke(), register it, and add it to a stack, usually on top of the default stack rather than replacing it. - How does type conversion work? Built-in converters turn request strings into numbers, dates and collections; custom converters handle other types. Failures are reported as field errors by the conversion error interceptor.
- How does Struts support internationalization? Resource bundles per action, package or globally, looked up through
getText()in actions and text tags in views, with locale taken from the request or session.
<struts>
<package name="orders" namespace="/orders" extends="struts-default">
<interceptors>
<interceptor name="audit" class="com.example.web.AuditInterceptor"/>
<interceptor-stack name="appStack">
<interceptor-ref name="audit"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="appStack"/>
<action name="save" class="com.example.web.SaveOrderAction" method="execute">
<result name="success" type="redirectAction">list</result>
<result name="input">/WEB-INF/jsp/orders/edit.jsp</result>
</action>
</package>
</struts>public class SaveOrderAction extends ActionSupport {
private String customerId;
private int quantity;
@Override
public void validate() {
if (customerId == null || customerId.isBlank()) {
addFieldError("customerId", getText("order.customer.required"));
}
if (quantity < 1) {
addFieldError("quantity", getText("order.quantity.min"));
}
}
@Override
public String execute() {
// call a service; never trust the client for prices or totals
return SUCCESS;
}
public void setCustomerId(String customerId) { this.customerId = customerId; }
public void setQuantity(int quantity) { this.quantity = quantity; }
}Senior: security, upgrades and migration
| Scenario | What it tests | What a strong answer shows |
|---|---|---|
| Why do security teams watch Struts applications closely? | Security history | Several critical remote code execution flaws have involved OGNL evaluation of attacker-controlled input, and one was widely reported as the entry point of a major data breach in 2017. Old, unpatched Struts versions are a known target. |
| How do you keep a Struts application safe? | Practice | Track the project's security bulletins, upgrade promptly, limit which parameters bind (allowlists rather than open binding), avoid evaluating user input as OGNL, use a dependency scanner in the build, and keep a web application firewall as a backstop, not a fix. |
| You inherit an application several major releases behind. How do you upgrade? | Upgrades | Read the migration notes for each step, add tests around critical flows first, upgrade in stages, watch for changed defaults in parameter handling and tags, and run security scans before and after. |
| How would you migrate from Struts to Spring MVC or Spring Boot? | Migration | Strangle it gradually: put both behind the same front, move one feature or URL group at a time, share the service and data layers, and retire Struts routes as their replacements go live, rather than a big-bang rewrite. |
| A user sees another user's data on a Struts 1 page. What do you suspect? | Thread safety | State stored in an action's instance field or a session-scoped form bean reused wrongly; move request data into local variables or request-scoped objects. |
| File uploads fail for large files. Where do you look? | Configuration | The multipart size limits in Struts constants and the container, the temporary directory, and the file upload interceptor's allowed types and size settings. |
| How do you test Struts actions? | Testing | Unit-test actions as plain classes where possible, with services mocked; use the framework's JUnit support for action mappings and interceptors; and keep end-to-end tests on the key flows before any upgrade. |
- What is action chaining, and why is it discouraged? The chain result forwards to another action while keeping the value stack. It couples actions tightly and hides flow, so a redirect to an action or a shared service is usually cleaner.
- How do you return JSON from a Struts 2 action? Through the JSON plugin's result type or a stream result, keeping the action's exposed properties limited to what the client should see.
- What is the difference between dispatcher and redirect results? Dispatcher forwards on the server within the same request, so the URL does not change. Redirect sends the browser to a new URL, which avoids resubmitting a form on refresh.
- How did Struts 1 handle form data? Through ActionForm beans declared in struts-config.xml, populated from the request and optionally validated before the Action ran, often with the Validator plugin.
- How do Tiles fit with Struts? Tiles composes pages from reusable layout pieces such as header, menu and body, and a Tiles result type lets actions return a layout definition instead of a single JSP.
Fictional example
- In my last role we had a claims system with about two hundred Struts 2 actions and a hard security deadline. I proposed two tracks. First, get safe: upgrade to a supported release, tighten parameter binding with allowlists, and add a dependency scanner to the pipeline so we would hear about new advisories the same week. Second, migrate gradually: new features went into Spring Boot controllers behind the same reverse proxy, sharing the existing service layer, and each quarter we moved one group of screens and deleted their actions. I insisted on end-to-end tests for the ten busiest flows before touching anything. We never had a big-bang cutover, and the Struts footprint shrank every release while the business kept shipping.
Preparation plan
- Trace a requestOn paper, follow a form post from the filter through each interceptor to the action, the result and the JSP, naming what each step adds.
- Read real configurationGo through a struts.xml or annotated actions from your past work or a sample project and explain every mapping and result.
- Study the security storyRead the project's own security bulletins and be able to explain the general OGNL injection pattern and how parameter allowlists help, without quoting numbers you have not checked.
- Compare with SpringMap Struts ideas to Spring MVC equivalents (action to controller, interceptor to handler interceptor or filter, value stack to model binding) using Spring Boot interview questions.
- Prepare a migration storyOne upgrade or migration you led or would lead, with how you limited risk. If the role also touches PHP frameworks, compare with Symfony.
Legacy framework interviews mix history, code and judgment, and answers tend to wander. Natively, an AI interview assistant for Mac and Windows, can transcribe a practice Struts interview on your computer and keep the transcript and notes, so you can tighten the request-flow explanation before the real call. While you rehearse it can read a screenshot of a struts.xml file or a stack trace and suggest how to explain it, and with Pro or the free trial it can use the résumé and job description you add.
Questions people ask
What Struts questions are asked in interviews?
Struts 1 versus Struts 2, the request flow through the filter and interceptors, actions and results, struts.xml, the value stack and OGNL, validation, type conversion, thread safety, security patching and migration to Spring.
What is the difference between Struts 1 and Struts 2?
Struts 2 is based on WebWork and uses a filter, plain action classes created per request, interceptors, the value stack and OGNL. Struts 1 uses ActionServlet, shared action instances and ActionForms, and is long past end of life.
Are Struts 2 actions thread-safe?
Yes in the usual setup, because a new action object is created for each request. Struts 1 actions are shared across requests, so instance fields there are a thread-safety bug.
Is Struts still used?
Mostly in existing enterprise applications. Interviews for those roles focus on safe maintenance, keeping up with security fixes and gradual migration to frameworks such as Spring.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
