Couldn't find action or result. No result defined for action in Struts 2

1.5k Views Asked by At

I have configured the annotation to return the values as text. But it's giving me the error: could not find action or result.

Console error:

org.apache.struts2.dispatcher.Dispatcher - Could not find action or result
/part!finder.xhtml
No result defined for action action.PartAction and result success

Action:

@Action(value="part!finder", results = {
    @Result(name="SUCCESS", type="stream", params = {"contentType", "text/html", "inputName", "inputStream"}),
    @Result(name="success", type="stream", params = {"contentType", "text/html", "inputName", "inputStream"})
}) 
public String finder() {
  try {
    inputStream = new ByteArrayInputStream(finder1().getBytes());
  }
  catch(Exception e) { }
    return SUCCESS;
  }
}
2

There are 2 best solutions below

0
On

If you're using DMI, apply @Action at the class level, and let DMI do the rest.

If you're annotating at the action level, declare a unique action name and don't use DMI.

(Or its syntax; it's confusing.)

2
On

Change the action name, that is a value attribute in the @Action annotation to value="part". ! is a special character used to separate action name and method name in the URL. But not in the action mapping. By adding ! in the action name mapping you make your action unreachable to action mapper that is searching for the action config that contains names without !. This char splits the action name and a method name, so it is inappropriate mapping in your action configuration.

BTW, when constructing URL and you have DMI turned on (which is by default is on) then better use a method attribute to url or submit tag and the correct url that maps to your action will be created after the JSP is rendered (result is processed). You could check the HTML outputed to the browser to see the source HTML code for the page. And you might find you action that is mapped to the (not default) method is prefixed by the ! sign. You could explicitly or via tags add the method to the action URL to execute method other than mapped with the action.