View Full Version : File Upload

29 Apr 2010, 4:16 PM

Because I could not find proper server-side sample for ExtGWT File Upload,
I have made upload with FormPanel for client side and "extends HttpServlet" for Server-side , not "extends RemoteServiceServlet ".

Problem is that I could not get any response such as Callback or HttpResponse of upload results
1. How can I get or handle the response after upload complete?

2. Is there no sample file uplod for server-side with "RemoteServiceServlet"? if it is, please let me know~


final FormPanel panel = new FormPanel();
panel.setHeading("File Upload Example");
btn.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
if (!panel.isValid()) {

// normally would submit the form but for example no server set up to
// handle the post

MessageBox.info("Action", "You file was uploaded", null);


public class AGISFileDispatcher extends HttpServlet {

public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
MyDispatcher a = new MyDispatcher();
a.saveFile(req, resp);

}catch(AgisException ex)


30 Apr 2010, 12:35 AM
Just to clarify:
Your code works, but you would like to modify it in such a way that the client is notified when the upload is complete?

30 Apr 2010, 12:46 AM
right. Upload works well, but client can not know whether upload is complete or not..

15 Oct 2010, 7:23 AM
// according to FormPanel.java (line 563, in v2.1.1):

fireEvent(Events.Submit, new FormEvent(FormPanel.this, impl.getContents(iframe))); (http://grepcode.com/file/repo1.maven.org/maven2/com.extjs/gxt/2.1.1/com/extjs/gxt/ui/client/widget/form/FormPanel.java#563)

I think that iFrame content will be updated on server response.
And you can use decode the response using the following :

form.addListener(Events.Submit, new Listener<FormEvent>() {
public void handleEvent(FormEvent be) {

Absence of server response decoding is an obvious GXT documentation flaw,
but there's a whole lot of work these men already managed to do for us.))

15 Oct 2010, 7:56 AM
Yes you get the response in that event, the Events.Submit event.

24 Sep 2012, 7:08 AM
Sven/GXT team -

This is an ongoing issue.

I'm not sure that Sven's comment "Yes, you get the response in that event" is accurate.

When I look at the event, in resultHtml I see something like this:

<h1>HTTP Status 501 - Q2Fubm90IGNyZWF0ZSBpbWFnZSB3aXRoIG5hbWUgdGVzdDMyMF8xMDAucG5nLiBUaGlzIGltYWdlIGFscmVhZHkgZXhpc3RzLg==</h1><hr size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>Q2Fubm90IGNyZWF0ZSBpbWFnZSB3aXRoIG5hbWUgdGVzdDMyMF8xMDAucG5nLiBUaGlzIGltYWdlIGFscmVhZHkgZXhpc3RzLg==</u></p><p><b>description</b> <u>The server does not support the functionality needed to fulfill this request (Q2Fubm90IGNyZWF0ZSBpbWFnZSB3aXRoIG5hbWUgdGVzdDMyMF8xMDAucG5nLiBUaGlzIGltYWdlIGFscmVhZHkgZXhpc3RzLg==).</u></p><hr size="1" noshade="noshade"><h3>Apache Tomcat/5.5.23</h3>

The common case here, is that we submit a form to create a server object based on the Form's model. In my case, this is complicated by the fact that I'm uploading a file (an image), which is part of what the server will use to create its object. However, a common scenario is to submit data from a form, and validate on the server whether an existing object with the same name/ID exists, and then send a response back with a status code and message like "The object could not be created, because it already exists". This "error" response would be caught in the submit request's callback, so that an informative message can be shown to the user.

How can this be accomplished with a FormPanel submit(), and in particular with a POST request - which is the only way I can see to upload a file/image.

Don P.

24 Sep 2012, 10:51 AM
The response you got back is a 501 error page as it looks like. The event always carries whatever the server returned, in case of error or success. In your case, it looks like the servlet that you used returned that page.

I would make the server to return xml/json formatted string in all the cases. This could be parsed in the client side so the client side can than show if it succeeded or failed.