struts2的json plugin能夠實現struts2和json的完美結合,struts2的官方文檔:http://struts.apache.org/2.2.1.1/docs/json-plugin.htmlhtml
剛剛整合struts2和json出現了個小問題There is no result type defined for type 'json',前端
在struts.xml中有以下action定義apache
<action name="menu" class="com.lsw.permission.action.MenuAction" method="getFunctionMenu"> <result name="success" type="json"> <param name="root">json</param> </result> </action>
在上面的定義中,action的result的type爲json,json plugin就可將action中定義爲groupList的field自動轉換爲json格式數據,並返回給前端UI。json
但在deploy後,啓動tomcat時卻報了There is no result type defined for type 'json' mapped with name 'success'. Did you mean 'json'?的錯誤,由於struts2找不到json這個result type的定義。解決方法有下面兩種:tomcat
1.將當前package的extends屬性改成"json-default",即讓當前package從josn-default繼承而不是struts-default繼承;app
2.但若是當前package確實沒法繼承"json-default"的話,還能夠在當前package中定義result-type,將json給加進去,以下:spa
<result-types><!-- 定義json類型 --> <result-type name="json" class="org.apache.struts2.json.JSONResult" /> </result-types>