在做dwr跨域调用时出现 Access-Control-Allow-Origin错误,后来搜了下,发现要做如下配置
dwr 2.0提供了 跨域访问的功能
dwr写道
Cross Domain Ajax: <script> tag manipulation
Should
you need to access servers in a different domain we've enabled a new
remoting scheme. From DWR 2.0 you can use manipulation of <script>
tags in addition to XMLHttpRequest or iframes. To use is you just need
to do the following:
DWREngine.setMethod(DWREngine.ScriptTag);
dwr 写道
To allow cross-domain script tag requests you need to add the following incantation to 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>
To configure the client where to send cross-domain requests, set the ._path variable for the remote interface in question:
Remote._path = 'http://otherdomain.com/webapp/dwr';
Remote.someFunction();
Cross-domain remoting may not work properly with reverse ajax.
实际开发
js 写道
<script type='text/javascript' src='http://a.com/dwr/interface/regutil.js'></script>
<script type='text/javascript' src='http://a.com/dwr/engine.js'></script>
<script type='text/javascript' src='http://a.com/dwr/util.js'></script>
js 写道
dwr.engine.setMethod(dwr.engine.ScriptTag);
regutil._path = 'http://sso.dxy.cn/dwr/';
调用方法 出现 XMLHttpRequest.open 时权限不足
网上搜索了下 很多人说是 firefox的bug
再次搜索 看到scripttag 能搞定此问题
把js 的引入 改成 动态 加载 果然可以了 哈哈
。
注意点:dwr jar需要是2.0.2
分享到:
相关推荐
很好的DWR2.0中文文档 深入浅出,通俗易懂, 学习dwr必备良书
DWR3.0.jar、DWR的实例war和DWR2.0中文说明文档
鄙视网上那些抄来抄去的,又不能用的垃圾 dwr2.0最简单例子实用亲测试
NULL 博文链接:https://liuzidong.iteye.com/blog/346042
作为一个java open source library,DWR可以帮助开发人员完成应用AJAX技术的web程序。它可以让浏览器上的javascript方法调用运行在web服务器上java方法。
NULL 博文链接:https://yxwang0615.iteye.com/blog/979630
dwr2.0 spring 3.0 整合示例
dwr2.0中文文档.pdf dwr2.0中文文档.pdf dwr2.0中文文档.pdf
DWR框架的jar包dwr-2.0RC1.jar
DWR2.0 相关配置文件 DWR2.jar + DWR.xml + DWR2.0.dtd + Web.xml
dwr-2.0.rc2-src (源代码)
jar包,官方版本,自测可用
DWR是一个Java开源库,帮助你实现Ajax网站。 它可以让你在浏览器中的Javascript代码调用Web服务器上的Java,就像在Java代码就在浏览器中一样。 DWR主要包括两部分: 在服务器上运行的Servlet来处理请求并把结果...
spring-dwr-2.0.xsd spring 与 DWR进行配置
Dwr2.0中文手册,详细的DWR API
dwr的入门实例,dwr2.0和3.0 jar包都有,可分别测试效果。用myeclipse important 项目,开启tomcat即可运行。
dwr 2.0 的 dtd 和官方网站首页 新鲜的,还热乎呢,回去好好用吧