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>