GWT:添加链接器(跨站点)不适用于服务器代码!
我正在尝试在 GWT 中进行一些跨站点操作。
根据GWT:同源策略 我已添加到模块 xml 文件中。
只要我不调用任何 GWT 远程服务(使用 GWT-RPC),它就工作正常,但是当我尝试调用任何远程服务时,我没有得到任何响应!
有人知道如何使用 GWT 远程服务解决 GWT 中的跨站点问题吗?
提前致谢!
I am trying to do some cross-site in GWT.
According to GWT:Same Origin Policy I've added to the module xml file.
It is working okey as long as I am not calling any GWT remote service (using GWT-RPC), but when I try to call any remote service, I got no response!
Any one know how to fix cross-site issue in GWT with GWT remote services?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Steve 的答案是正确的,但是如果您想在不使用 OAUTH 的情况下要求对服务器交互进行身份验证,那么您可以考虑另一种选择,这是最好的方法。主要的一点是,跨站点链接器不会绕过 SOP,但允许您将 index.html 托管在与 JS 代码不同的站点上,以便您可以在一台服务器上拥有 JS 代码和 servlet 并加载它们来自另一个。要绕过 SOP,您可以使用名为 JSON with padding 或 JSONP 的方法。本质上,它的作用是使用脚本标记通过将请求的数据包装在回调中来将外部请求注入到环境中。为此,您可以使用许多服务器端实现之一,例如 Jersey。 GWT 2 包含一个 JsonpRequestBuilder 对象,它为您完成所有客户端工作,并且可以按照与 RequestBuilder 相同的方式使用。请参阅此教程文章。
Steve's answer is correct, however there is one other option you can consider which is the best approach if you want to require authentication for server interaction without using OAUTH. The main point is that the cross-site linker doesn't bypass the SOP, but allows you to host the index.html on a different site than the JS code so that you can have the JS code and servlets on one server and load them from another. To get around the SOP you can use a method called JSON with padding or JSONP. Essentially what it does is use a script tag to inject a foreign request into the environment by wrapping the requested data in a callback. To do this you can use one of many server-side implementations such as Jersey. GWT 2 includes a JsonpRequestBuilder object which does all the client-side work for you and can be used in the same way as RequestBuilder. See this article for a tutorial.
如果您想从 GWT 应用程序访问其他服务器 (example.com),那么您必须对您的服务器执行 RPC,并且在服务器端代码中,您必须对您正在寻找的 example.com 页面。
您链接到的有关跨站点链接的页面概述了将
添加到模块文件允许您在 2 台服务器之间拆分托管:If you want to access some other server (example.com) from your GWT app, then you'll have to do an RPC to your server, and in your server-side code, you'll have to make another HTTP call to the example.com page you're looking for.
The page you linked to regarding cross-site linking outlines that adding
<add-linker name="xs"/>
to the module file allows you to split your hosting between 2 servers: