Struts 2 - No result defined for action and result input With Examples

Recently while working on a Struts 2 project, I got a strange error message No result defined for action and result input.

Struts2 – No result defined for action and result input

Let’s look at a simple scenario where we get the error message “No result defined for action and result input”.

My project had a simple JSP page like below.

login.jsp

And corresponding action class as:

LoginAction.java

My struts 2 configuration file was like below.

struts.xml

Everything looked fine and when login action will be invoked, LoginAction will take care of it. Incase of success, welcome.jsp will be sent as response or error.jsp incase of any errors.

But whenever I tried to invoke login action without passing username or password values, I get 404 error and browser response as:

No result defined for action com.journaldev.struts2.action.LoginAction and result input

And in server logs, I was getting following exception stack trace:

Fix – No result defined for action and result input

I was clueless for sometime as what is going on, then I looked at the message and it says that “no result is defined for input“. So I modified my login action like below.

This simple change solved the issue and I was getting login.jsp page as response with error message set in the validate() method of LoginAction.

The reason is that “input” is the default result returned by Struts 2 whenever there is a problem with validating the parameters passed to an action.

I hope this quick solution will save someone’s time when working with Struts 2 and using form fields validation.

By admin

Leave a Reply

%d bloggers like this: