Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all you need a <a href="http://commons.apache.org/proper/commons-fileupload/" rel="nofollow">servlet in Tomcat</a></p> <p>Then send the image to the servlet using <a href="https://code.google.com/p/gwt-html5-wrappers/source/browse/trunk/src/com/pixeljet/html5/client/FormData.java?r=2" rel="nofollow">FormData</a> and <a href="https://code.google.com/p/gwt-xmlhttprequest2/source/browse/src/com/google/gwt/xhr/client/XMLHTTPRequest2.java?r=1ca8108b439f38a945223eeffd1343e9f48d5e44" rel="nofollow">XMLHTTPRequest2</a></p> <p>You need to getthe image from the DOM, and then do something like that:</p> <pre><code>String url = GWT.getHostPageBaseURL() + "UploadFileServlet?sid=" + AppHelper.remoteService.getSessionID(); XMLHTTPRequest2 xhr = (XMLHTTPRequest2) XMLHTTPRequest2.create(); xhr.open("POST", url); FormData formData = FormData.create(); formData.append("file", imagedata); xhr.setOnReadyStateChange(new ReadyStateChangeHandler() { //@Override public void onReadyStateChange(XMLHttpRequest xhr) { /////Window.alert(" " + xhr.getStatus()); // When the form submission is successfully completed, this event is // fired. Assuming the service returned a response of type text/html, // we can get the result text here (see the FormPanel documentation for // further explanation). //Window.alert(event.getResults()); String result = xhr.getResponseText(); if(result.equals("ok")) { Window.alert("File uploaded"); } else { Window.alert(result); } } }); xhr.send(formData); </code></pre> <p><strong>This is the FormData class</strong></p> <pre><code>public class FormData extends JavaScriptObject { //default constructor //see more at http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#formdata protected FormData() { } /** * add a pair of value to form. * &lt;p&gt; * See &lt;a href="http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#formdata" * &gt;http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#formdata&lt;/a&gt;. * * @param name the name to be add * @param value the value to be add */ public final native void append(String name, String value) /*-{ this.append(name, value); }-*/; public final native void append(String name, JavaScriptObject value) /*-{ this.append(name, value); }-*/; /** * Creates an XMLHttpRequest object. * * @return the created object */ public static native FormData create() /*-{ return new FormData(); }-*/; } </code></pre> <p><strong>And this is XMLHttpRequest2 class</strong></p> <pre><code>public class XMLHTTPRequest2 extends XMLHttpRequest { /** * Constructor */ protected XMLHTTPRequest2() { } /** * Initiates a request with data. If there is no data, specify null. * &lt;p&gt; * See &lt;a href="http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#dom-xmlhttprequest-send" * &gt;http://dev.w3.org/2006/webapi/XMLHttpRequest-2/#dom-xmlhttprequest-send&lt;/a&gt;. * * @param requestData the data to be sent with the request */ public final native &lt;T&gt; void send(T requestData) /*-{ this.send(requestData); }-*/; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload