开发者

Accessing a file in another server from GWT Client side

I have a file, sample.xml located at one web server. I want to access this file from a GWT application running at another server. I dont want to make RPC calls to the sam开发者_JS百科e server serving GWT application and access the required file on server side (like a proxy). I want to access the file directly from client side as my application is going to be hosted as static files in a web server.

Is there a way to do that?


Sure - you must issue a XHR (XmlHTTPRequest) from the browser, and then parse the data.
In GWT you can do it using the RequestBuilder class (see here).

Please note that some client side restrictions may apply (e.g. Single Origin Policy etc.)

You issue the request (GET or POST - GET in your case) and pass a callback instance.
The instance's onResponseReceived method receives a Response object, which by calling its getText method returns the received contents.


You're trying to have your website (a.com/index.html) reference b.com/sample.xml. I see a few options.

If you have access to b.com's servers:

  • Edit sample.xml into sample.js to contain the same information in JSON with a callback, and reference it with a script tag
  • Compile your website using the cross-site loader (see Controlling Compiler Output), put your index.html at b.com/index.html, put all the rest of your files on a.com. Then all your RPC calls can go to b.com, but this means the user would have to navigate to b.com instead of a.com

If you don't have access to b.com's servers: - Simply provide a link for people to download sample.xml - Host a.com on a server with some kind of script support (PHP, Python, Ruby, Java, anything) and put a proxy to b.com/sample.xml

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜