Home >Java >javaTutorial >Why is my Struts2 JSON Plugin AJAX Call Returning an 'Unable to Find Action or Result' Error?
Scenario:
You are using the Struts2 JSON plugin in an AJAX call, but the response is not returning JSON data. Instead, you receive an error message:
org.apache.struts2.dispatcher.Dispatcher - Could not find action or result No result defined for action action.Part and result {"col1":"col1","col2":"col2"}
Cause:
The error occurs because the action is not returning the correct type of data. The JSON plugin expects the action to return an object that can be serialized into JSON format. However, in this case, the action is returning a custom object that is not serializable.
Solution:
To resolve this issue, you can use the root parameter in the struts.xml file to specify the root object that should be serialized. The root object must be a public field or a getter method in the action class.
Example:
<result type="json"> <param name="root">rows</param> </result>
In this example, the rows field in the action class is the root object that will be serialized into JSON.
Additional Tips:
The above is the detailed content of Why is my Struts2 JSON Plugin AJAX Call Returning an 'Unable to Find Action or Result' Error?. For more information, please follow other related articles on the PHP Chinese website!