The solution of no result type defined for type 'json' appears when struts2 integrates json

Missing jar package


The json plugin of struts2 can realize the perfect combination of struts2 and json. Since this article mainly introduces the problems encountered in the integration process, the programming method will not be repeated here. For details, please refer to the official documents of struts2: http:// struts.apache.org/2.2.1.1/docs/json-plugin.html .

I have the following action definition in struts.xml:

<action name="product_group" class="customers.products" method="getGroups">
<result type="json">
<param name="root">groupList</param>
</result>
</action>

In the above definition, the type of the result of the action is json, and the json plugin can automatically convert the field defined as groupList in the action into json format data and return it to the front-end UI.

But after deploy, the error There is no result type defined for type 'json' mapped with name 'success'. Did you mean 'json'? is reported when starting tomcat , because struts2 cannot find the definition of the result type json . There are two solutions:

1. Change the extends property of the current package to "json-default" , that is, let the current package inherit from josn-default instead of struts-default;

2. But if the current package really cannot inherit "json-default", you can also define result-type in the current package and add json , as follows:

<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>

Principles of the two methods:

The result type of json is defined in json-default (struts2-json-plugin-2.1.8.1.jar\struts-plugin.xml), and the content is as follows (xml and doctype tags are omitted):

copy code
<struts>
<package name="json-default" extends="struts-default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
</interceptors>
</package>
</struts>
copy code

It can be seen that the result type whose name is "json" is defined in json-default, so the result of json can be used by inheriting from json-default. In addition, json-default also defines an interceptor named "json".

In addition, according to the definition of json-default, it is more appropriate to add a json interceptor definition in method 2.



Reprinted from: https://www.cnblogs.com/ini_always/archive/2011/10/15/2213404.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325534331&siteId=291194637