Because Content-Types are so often wrong on the internet (particularly when 
set to text/html or text/plain), browsers use 
content-sniffing<http://mimesniff.spec.whatwg.org/>. 
Because your response does not look like HTML, it might very-well be 
sniffed as text/plain by the browser, which will then skip the 
onSubmitComplete.
Try prepending "<html><body>" to your response so that browsers will 
"sniff" it as text/html (or in other words, send back HTML, not something 
that's only *labelled* as being HTML)

On Monday, November 12, 2012 1:11:48 PM UTC+1, Thomas Lefort wrote:
>
> I implemented a simple image uploader which relies on the form panel. I 
> pass an image file via a filupload widget and a multipart encoding to the 
> server which then processes the image, stores it on the disk and returns 
> the image file path as a text/html response. On the client side I have an 
> onSubmitCompleted event handler that sets the image widget url to the one 
> returned by the servlet.
>
> The onSubmitCompleted handler is sometimes (actually quite often) not 
> called. I checked with firebug, the servlet does return the right file 
> path, the image is stored, etc... The servlet also gets fully executed with 
> no error (checked with various traces). I have the behavior for (at least) 
> FF16. I have the issue in hosted mode or in compiled ran locally (with the 
> embedded jetty).
>
> Here's my servlet code:
>
>     @Override
>     protected void doPost(HttpServletRequest request, HttpServletResponse 
> response)  throws ServletException, IOException {
>         response.setContentType("text/html");
>         PrintWriter writer = response.getWriter();
>         try {
>             // default values for width and height
>             int width = 50;
>             int height = 50;
>             InputStream filecontent = null;
>             String saveFile = null;
>             List<FileItem> items = new ServletFileUpload(new 
> DiskFileItemFactory()).parseRequest(request);
>             for (FileItem item : items) {
>                 if (item.isFormField()) {
>                     String fieldName = item.getFieldName();
>                     String fieldValue = item.getString();
>                     if(fieldName.equalsIgnoreCase("width")) {
>                         width = Integer.parseInt(fieldValue);
>                     }
>                     if(fieldName.equalsIgnoreCase("height")) {
>                         height = Integer.parseInt(fieldValue);
>                     }
>                 } else {
>                     String fieldName = item.getFieldName();
>                     saveFile = FilenameUtils.getName(item.getName());
>                     if(fieldName.equalsIgnoreCase("image")) {
>                         filecontent = item.getInputStream();
>                     }
>                 }
>             }
>             // check values
>             if(filecontent == null) {
>                 throw new FileNotFoundException("no file provided");
>             }
>             // Process the input stream
>             ByteArrayOutputStream out = new ByteArrayOutputStream();
>             int len;
>             byte[] buffer = new byte[8192];
>             while ((len = filecontent.read(buffer, 0, buffer.length)) != 
> -1) {
>                 out.write(buffer, 0, len);
>             }
>
>             String imagePath = processAndStoreImage(out, saveFile, width, 
> height);
>             System.out.println(imagePath);
>             
>             // return the url of the file
>             writer.println(imagePath);
>
>          } catch (Exception e) {
>             writeError(writer, "Error whilst processing and storing 
> image.");
>         } finally {
>             writer.flush();
>             writer.close();
>         }
>
>     }
>
> and the onSubmitHandler
>
>         imageForm.addSubmitCompleteHandler(new 
> FormPanel.SubmitCompleteHandler() {
>             public void onSubmitComplete(SubmitCompleteEvent event) {
>                 final String result = event.getResults();
>                 // update thumbnail view with new image
>                 thumbnailImage.setUrl(result);
> Window.alert("YES");
>             }
>         });
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-web-toolkit/-/eMBaAfyh4VgJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to