View Full Version : Parsing upload response

1 Sep 2010, 6:17 AM

is there any support by the GXT framework for parsing an upload response. We are using a FormPanel like this:

formPanel.setAction(GWT.getModuleBaseURL() + "MyServlet");
formPanel.addListener(Events.Submit, new Listener<FormEvent>() {
public void handleEvent(final FormEvent event) {

The result from the server (event.getResultHtml()) is, as the name implies, is HTML encoded although we write plain text at the server:

final PrintWriter out;
try {
out = response.getWriter();
if (!success) {
} else {

In this example the response would be "<PRE>success</PRE>" respectively "<PRE>failure</PRE>", but not "success" or "failure".

The problem is that more complex responses would lead to quite complex "html documents" that are error-prone to parse. Moreover different browser will generate different html responses so that it is nearly impossible to parse them in general.

Are there any best practices for this problem or are we doing anything wrong?


1 Sep 2010, 6:20 AM
Only FireFox wraps it into pre tags if you send the wrong contenttype from the server. What contenttype do you set on your server?

1 Sep 2010, 6:23 AM
We've tested it with FF 3.6 and IE 8 and both wrap it into pre tags. We've set the contenttype to "text/plain".

1 Sep 2010, 6:25 AM
set the contentype to
Content-Type: text/html
and it wont wrap it.

I would return some json string from the servlet as that is easy to parse on the clientside.

1 Sep 2010, 6:25 AM

1 Sep 2010, 6:42 AM
Thanks for your help. Using text/html works as expected. We will use json for our responses.

Note: If the response is something like "Hello<World>" the result is:

in IE: "Hello<World>"
in FF: "Hello<World></World>"

This is not really a problem for us, but you have to make sure that you don't use any angle brackets in your response text.

1 Sep 2010, 6:50 AM

depending on your exact needs you can also use text/plain as contenttype and remove the pretags again(if they are there).

1 Sep 2010, 11:05 AM
I am about to do a form upload and I am wondering if my RPC servlet can handle the upload, would I have to set the form's action to another servlet e.g
formPanel.setAction(GWT.getModuleBaseURL() + "MyServlet");
or can a RPC servlet handle file uploads. Hope my question is not funny :)

1 Sep 2010, 11:07 AM
The RPC servlet cannot automatically handle it without any code changes. You should start with an own servlet that directly access the doPost method.

Else you need to do overrides to the rpcservlet and based on the data that is received switch between form post and real rpc request.

1 Sep 2010, 12:42 PM
Alright, I'll use another servlet, thanks.

2 Sep 2010, 1:44 AM
This has been resolved here (http://www.sencha.com/forum/showthread.php?104461-How-To-Upload-Images-to-the-Server&p=508130#post508130)