无法将Struts2结果类型设置为json [英] can't set Struts2 result type to json
问题描述
我想在Struts2中使用json.但是,当我将操作返回类型设置为"json"时,得到没有为映射为名称'success'的'json'类型定义任何结果类型".波纹管是struts.xml文件.
I want to use json with Struts2. However, when I set the action return type to "json", I got "there is no result type defined for type 'json' mapped with name 'success'." Bellow is struts.xml file.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="resource"/>
<package extends="struts-default" name="test">
<action name="inputHandler" class="inputHandlerAction">
<result name="input">/index.jsp</result>
<result>/result.jsp</result>
</action>
<action name="setLangHandler" class="com.sesoft.test.setLanguageHandler">
<result>/index.jsp</result>
</action>
<action name="Handler" class="com.sesoft.test.Handler">
<result>/test2.jsp</result>
</action>
</package>
<package name="example" extends="json-default">
<action name="ajaxHandler" class="com.sesoft.test.AjaxHandler">
<result name="success" type="json" />
</action>
</package>
</struts>
在添加json动作之前,所有其他动作均能正常运行.但是在添加json Action之后,服务器无法操作,错误代码为503.
Before I added the json Action, all other action performs fine. But after I added the json Action, the server failed to action with error code 503.
库我已将"jsonplugin-0.33.jar"添加到库目录.
libs I've added "jsonplugin-0.33.jar" to the lib directory.
推荐答案
您没有在struts.xml包中定义JSON结果.如果只需要默认值,则可以扩展json-default而不是struts-default.如果您需要自定义程序包,则请包含以下内容并可以解决问题:
You don't have the JSON result defined in your struts.xml package. If you only need default things then you can just extend json-default instead of struts-default. If you need to customise the package then include the following and that should do the trick:
<result-types>
<result-type name="json" class="com.googlecode.jsonplugin.JSONResult"/>
</result-types>
这篇关于无法将Struts2结果类型设置为json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!