0

I am trying to download a file from server. The normal GWT RPC call doesnot allow me to do that, and hence I wrote a servlet to do that job for me. From the client side, I am creating a Frame object, and I set the servlet URL in it, and add that frame Object in my root panel. When I execute this in IE, a window pops up asking for Save/Open file. But when I execute the same in a Firefox or a Google Chrome browser, nothing is happing. I am not getting any request on my servlet/server side. Here is a slice of the code :-

String servletUrl = "http://localhost:13080/Browser/ui/dataExportServlet?level=ZERO";

          Frame frame = new Frame(servletUrl);
    frame.setVisible(false);
    RootPanel.get().add(frame);

So, can someone please help me out.

3 Answers3

0

This might be related to same origin policy. Are both servlet and webapp running on port 13080? If they differ, SOP might fail this. If I understand correctly, IE has a more relaxed policy so it might work there but not in chrome.

See http://en.wikipedia.org/wiki/Same_origin_policy and Can I disable SOP (Same Origin Policy) on any browser for development?

Community
  • 1
  • 1
Yoni Roit
  • 28,280
  • 7
  • 36
  • 32
  • Ya, both are running on the same port. If I paste the servlet URL directly in chrome/mozilla, I get the pop-up. So, my servlet is working fine. But if I invoke it through GWT Applictaion, by Frame, the request doesnot reach the servlet.... – Ajay Tushir Feb 09 '11 at 16:48
0

In Chrome, you can use the Developer Tools (CTRL + SHIFT + I) to check if the IFrame is being added to the HTML, and if the frame's source is being set properly. You should also be able to see what content has been loaded into the iframe.

Alternately, set a breakpoint in your servlet to see if the iframe is being hit at all from Chrome.

Steve Armstrong
  • 5,252
  • 7
  • 32
  • 43
  • Hi Steve, I checked in Chrome, using the Developer Tools. In the "Network" tab, it shows the servlet name, and the "Status" column says Pending. If I see the "Console" tab, it says "Failed to load resouce", and the resouce is my servlet. When I hover the mouse over the servlet name, it shows me the correct URL of that servlet. If I take that URL and paste in the browser, it behaves as expected. So, that means, the servlet is deployed properly, in the web-container. So, can you please suggest me, what I need to make it work.... – Ajay Tushir Feb 10 '11 at 05:18
  • I did some further investigation. In Chrome, I am unable to hit the servlet at all via the GWT application, but in Mozilla Firefox, I see that the request is getting passed to the servlet, it gets the data generated, and returns the result properly (which is actually a CSV file), but the pop-up window is not getting populated at the client side. I really need to fix this issue atleast in Mozilla..... – Ajay Tushir Feb 10 '11 at 06:55
0

I got the solution for this issue. I removed the frames and added the following code :-

com.google.gwt.user.client.Window.open(url, "CSVDownload", "");

Now, this opens a new browser window, and then I get the pop-up to open/save the server side file in all 3 web-browsers. (IE, Mozilla FireFox, Chrome).

Thanks a lot!!!