views:

669

answers:

1

I have Application written with GWT 1.7. I have one page where I upload file to the remote server that is on different domain. So, when I do Post to the server files goes to the server but when it's time to get response I'm getting null in following function:

Servlet:

...
resp.setStatus(HttpServletResponse.SC_CREATED);
resp.getWriter().print("The file was created successfully.");
resp.flushBuffer();
...

GWT:

form.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
      public void onSubmitComplete(SubmitCompleteEvent event) {
       Window.alert(event.getResults());
      }

Javadoc for event.getResults() said following:

Returns: the result html, or null if there was an error reading it @tip The result html can be null as a result of submitting a form to a different domain.

This is the code example that I tried to follow. It works as is, but when I'm calling my servlet the response is null.

By the way I tried to use Firebug to see Headers and it seems to me that servlet is sending response back. I think it's just GWT does not like it. Is there any work around for this so I can get my response in GWT?

Thanks

+3  A: 

Not to state the obvious but it says right in the quote you posted what is wrong:

The result html can be null as a result of submitting a form to a different domain.

It looks like the code sample you link to is on the same domain so it's not violating the same origin policy for the browser.

There's this workaround but it seems to be for earlier version of GWT and only works for Firefox.

seth
So, there is no way of getting response from the remote server? Is there any other technologies/techniques I can use to get that message from the server?
Maksim
You could use a JS library (or something you write) that dynamically inserts a script tag. Here's an article about it: http://jaybyjayfresh.com/2007/09/17/using-script-tags-to-do-remote-http-calls-in-javascript/ Most of the major JS libs do this out of the box. Not 100% sure how you would incorporate it into GWT though.
seth