Fix Struts 2 No Result Defined for Action and Result Code
Fix the Struts 2 missing result error by mapping the code the action returned, usually input after a validation failure, and checking the package.

A form submit shows a blank error page and the log has this line:
com.opensymphony.xwork2.config.ConfigurationException: No result defined for action dev.javahacks.web.LoginAction and result inputStruts maps what an action returns, a string such as success or error, to a result: a JSP, a redirect or a stream. The mapping lives in struts.xml. If the action returns a name nobody mapped, Struts has nowhere to send the response and throws. The flow of a request through an action is in what Struts 2 is, and the configuration elements in configuring actions, results and interceptors.
The common cause: input
The word in the message is the clue. If it says input, a validation or conversion step failed before your action's execute ran. The workflow interceptor sees field errors and returns input to send the user back to the form with the errors.
<struts>
<package name="default" extends="struts-default">
<action name="login" class="dev.javahacks.web.LoginAction">
<result name="success">/welcome.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
</struts>With the input result mapped, a failed validation re-renders login.jsp, and the <s:fielderror /> or the form's own error display shows the messages. Without it, you get the exception above, and the user sees nothing helpful. Any action that accepts form input needs this result. How validation produces the code is in validating input in Struts 2.
A string your action returns that you never mapped
public String execute() {
if (!service.authenticate(username, password)) {
return "denied"; // no <result name="denied"> exists
}
return SUCCESS;
}Either map denied or return a name you already have, such as error or input. Use the constants from Action (SUCCESS, ERROR, INPUT, LOGIN, NONE) to avoid typos; "succes" is a surprisingly common cause.
Share results with a global result
<package name="default" extends="struts-default">
<global-results>
<result name="error">/error.jsp</result>
<result name="login" type="redirectAction">login</result>
</global-results>
...
</package>A global result is found if the action has no local one of that name. It prevents repeating error in fifty actions. Local results override the global ones.
It is in the wrong package
Results are resolved inside the package the action belongs to and the packages it extends. An action declared in a package that does not extend struts-default also lacks the default interceptor stack. If you split configuration across several files with <include>, check which package each action is in and that the file is included.
Method call syntax
When you call a method other than execute, the result is looked up for what that method returns:
<action name="user-*" class="dev.javahacks.web.UserAction" method="{1}">
<result name="success">/user.jsp</result>
</action>If UserAction.delete() returns "deleted", the wildcard action needs a deleted result. Struts also restricts which methods can be called this way, a setting tied to security in hardening Struts 2.
Reproduce the error in a test
The fastest way to stop guessing is to ask Struts what it will do for a given result name. The struts2-junit-plugin ships StrutsJUnit4TestCase, which loads your real struts.xml and executes an action through the full interceptor stack. A test that fails with the same message gives you a repeatable check, and the same test proves the fix.
public class LoginActionTest extends StrutsJUnit4TestCase<LoginAction> {
@Test
public void blankUsernameReturnsToTheForm() throws Exception {
request.setParameter("username", "");
request.setParameter("password", "change-me");
ActionProxy proxy = getActionProxy("/login");
String result = proxy.execute();
assertEquals("input", result);
assertTrue(proxy.getInvocation().getAction() instanceof LoginAction);
}
@Test
public void everyResultTheActionCanReturnIsMapped() throws Exception {
ActionConfig config = configuration.getRuntimeConfiguration()
.getActionConfig("", "login");
assertTrue(config.getResults().containsKey("input"));
assertTrue(config.getResults().containsKey("success"));
}
}The first test drives the validation path and asserts the code. The second reads the compiled configuration, which includes global results from the package, and checks the codes the action can return. Add one assertion per code. When someone later returns a new string from execute(), the build fails with a name instead of a user seeing a blank page.
Declare the codes with validation, not with luck
A form action can return input from four places, and only one of them is code you wrote. Knowing which one fired tells you whether the fix is a mapping or a bug.
public class LoginAction extends ActionSupport {
private String username;
private String password;
@Override
public void validate() {
if (StringUtils.isBlank(username)) {
addFieldError("username", getText("login.username.required"));
}
}
@Override
public String execute() {
return authenticate(username, password) ? SUCCESS : ERROR;
}
// getters and setters omitted
}validate() adds field errors, and the workflow interceptor then returns input before execute() runs. The params interceptor can add conversion errors too: posting age=abc to an int property produces a conversion error and an input result with no code from you. A validation.xml file beside the action class, or @RequiredStringValidator annotations, add a third source, and the ActionSupport base class adds the fourth through addActionError. In all four cases the mapping is the same, one <result name="input">.
Read the log to see which result was looked up
Struts logs its decisions at debug level. Turn on the com.opensymphony.xwork2 category and the line before the exception tells you the package and the action it searched.
logger.xwork.name = com.opensymphony.xwork2
logger.xwork.level = debug
logger.struts.name = org.apache.struts2
logger.struts.level = debugWith debug on, DefaultActionInvocation logs the result code, which is the string execute() returned, with no guessing about spelling or case. Struts compares result names exactly, so Input is not input, and a trailing space in a return "input " also fails.
Types of result, and why the default matters
A <result> with no type attribute uses the package's default result type, which for struts-default is dispatcher, a server-side forward to a JSP. The other types decide how the response is built, and picking the wrong one produces symptoms that look like this error.
| Type | Use it when |
|---|---|
dispatcher | the result is a JSP, and the URL should stay as the action's |
redirect | the result is another URL, after a state change |
redirectAction | the result is another action, which is the post-redirect-get pattern |
stream | the action returns a file or a generated image |
json | the struts2-json-plugin is installed and the client wants JSON |
After a successful login or a save, use redirectAction so a browser refresh does not resubmit the form. Pass the id along as a parameter in the result: <param name="id">${id}</param>.
A checklist when the message names a code you did map
If the result exists in struts.xml and the error persists, the file Struts loaded is not the one you edited. Check that the struts.xml in WEB-INF/classes of the deployed war is the new one, that no second struts.xml earlier on the classpath shadows it, and that the <package> containing the action has no abstract="true" attribute. A package with a namespace also changes the URL, so /admin/login and /login are different actions with different result tables.
Where this does not apply
If the exception is about a missing action, the URL or namespace is wrong (There is no Action mapped for namespace). If the result exists and the page is blank, the JSP path is wrong or the response was already committed. The Struts result documentation and the getting started guide cover result types.


