IOS开发-跨域访问DWR方法
用Phonegap做手机客户端,服务器用spring+DWR,需要在手机端访问服务器的方法,需要做以下配置,可以参见http://www.iteye.com/topic/337460:
服务器DWR配置(web.xml):
<init-param> <param-name>allowGetForSafariButMakeForgeryEasier</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>crossDomainSessionSecurity</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>allowScriptTagRemoting</param-name> <param-value>true</param-value> </init-param>
手机客户端JS
<script type='text/javascript' src='/Ajax_chat/dwr/engine.js'></script> <script type='text/javascript' src='/Ajax_chat/dwr/util.js'></script> <script type="text/javascript" src='http://www.myspace.com:8080/DWR_cross/dwr/interface/TestCross.js'></script> <script type="text/javascript"> function sendMsg(){ TestCross._path="http://www.myspace.com:8080/DWR_cross/dwr; TestCross.greeting(DWRUtil.getValue("userName"),function(data){alert(data);}); } </script>
其他服务器端的java、dwr.xml没有特殊之处。需要指出的是客户端js中第3行为需要跨站的DWR方法所在,至于第1、2行,根据需要来吧。