1:下载Axis2的war包,并且安装在你的Servlet容器中(tomcat放在webapps目录下),下载地址:http://axis.apache.org/axis2/java/core/download.cgi
2:下载DynamicResponseHandler(wso2dynamic-response-1.5.mar)模块,复制到
webservice项目中的WEB-INF/modules中,下载地址:http://dist.wso2.org/maven2/org/wso2
/dynamicresponse/wso2dynamic-response/1.5/
3:下载Jettison,放入WEB-INF/lib中的模块,下载地址:http://jettison.codehaus.org/Download
以及下载Jettison1.2补丁jettison-1.2-patched.jar,放入WEB-INF/lib中的模块,下载地
址:http://www.marcusschiesser.de/wp-content/uploads/2009/01/jettison-1.2-
patch.zip.zip
注:如果有,删除jettison-1.0-RC2.jar。
4:将axis2.xml(定位在WEB-INF/conf)配置文件中的添加
<module ref="DynamicResponseHandler"/>
5:在axis2.xml添加JSON消息格式:
<messageFormatters>
<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/>
<messageFormatter contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>
</messageFormatters>
6:在axis2.xml添加JSON消息编译
<messageBuilders>
<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONOMBuilder"/>
<messageBuilder contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/>
</messageBuilders>
7:启动你的服务容器,并且通过url测试,例如:
http://localhost:8080/axis2/services/Version/getVersion?response=application/json
自己写的服务启用json格式:
http://localhost:8080/webservicetest/services/TestWS/getInfo?response=application/json
http://localhost:8080/webservicetest(工程名)/services/TestWS(类名)/getInfo(方法名)?str(传递的参数名,要和方法中传递的参数名一致)=tom(传递的参数值)
转自 http://zfwdl2005.iteye.com/blog/2019429