Struts 2 – No result defined for action and result input

Filed Under: Struts 2

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

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


<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%-- Using Struts2 Tags in JSP --%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Login Page</title>
</head>
<body>
<h3>Welcome User, please login below</h3>
<s:form action="login">
	<s:textfield name="name" label="User Name"></s:textfield>
	<s:textfield name="pwd" label="Password" type="password"></s:textfield>
	<s:submit value="Login"></s:submit>
</s:form>
</body>
</html>

And corresponding action class as:

LoginAction.java


package com.journaldev.struts2.action;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {

	@Override
	public String execute(){
		//Some complex business logic
		return SUCCESS;
	}
	
	@Override
	public void validate(){
		if("".equals(getName())){
			addFieldError("name", "UserName can't be empty");
		}
		if("".equals(getPwd())){
			addFieldError("pwd", "Password can't be empty");
		}
	}
	
	//Java Bean to hold the form parameters
		private String name;
		private String pwd;
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getPwd() {
			return pwd;
		}
		public void setPwd(String pwd) {
			this.pwd = pwd;
		}
}

My struts 2 configuration file was like below.

struts.xml


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.convention.result.path" value="/"></constant>
<package name="user" extends="struts-default">
	<action name="home">
		<result>/login.jsp</result>
	</action>
	<action name="login" class="com.journaldev.struts2.action.LoginAction">
	<result name="SUCCESS">/welcome.jsp</result>
	<result name="ERROR">/error.jsp</result>
	</action>

</package>

</struts>

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:


Sep 14, 2013 11:40:25 PM com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
SEVERE: Exception occurred during processing request: No result defined for action com.journaldev.struts2.action.LoginAction and result input
No result defined for action com.journaldev.struts2.action.LoginAction and result input
	at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
	at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
	at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)

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.


<action name="login" class="com.journaldev.struts2.action.LoginAction">
	<result name="SUCCESS">/welcome.jsp</result>
	<result name="ERROR">/error.jsp</result>
	<result name="input">/login.jsp</result>
</action>

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.

Comments

  1. huy says:

    I have same problem. But this is too helpful . I try to solve it by anyway . And now after read your page, i’m done now ! thanks u

  2. prakash says:

    your posts are very useful. specially above mentioned struts2 error , chewed my head for days , finally got the solution.

  3. Durgesh Patel says:

    you are intelligent thanks bhai your website is very helpful for me.

  4. navaneetha says:

    while uploading a picture into application form i got the error ….. No result defined for action actions.UploadPhotoAction and result input…..what dpes it mean

    1. sunny says:

      i have got the same error.

      would you tell me how to issue that.

      thx very much !

  5. Vivek says:

    I solved my issue by your post. Thanks

  6. Tan Pham says:

    Thank you very much. Your website is really helpful for me to study struts 2.

  7. Saggie says:

    Thanks A Lot…

  8. Moh Samiullah says:

    Thanks alot.. this is really helpful for me. I spent almost couple of days before coming to this.

    1. VK says:

      Useful post .Thanks a ton 🙂

  9. Hariramanan T says:

    This is very helpful for me,I also got this problem,

    thanks for this tips

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages