-
1 Sep 2010 6:17 AM #1
Parsing upload response
Parsing upload response
Hi,
is there any support by the GXT framework for parsing an upload response. We are using a FormPanel like this:
The result from the server (event.getResultHtml()) is, as the name implies, is HTML encoded although we write plain text at the server:Code:formPanel.setAction(GWT.getModuleBaseURL() + "MyServlet"); formPanel.setEncoding(Encoding.MULTIPART); formPanel.setMethod(Method.POST); formPanel.addListener(Events.Submit, new Listener<FormEvent>() { @Override public void handleEvent(final FormEvent event) { System.out.println(event.getResultHtml()); } }
In this example the response would be "<PRE>success</PRE>" respectively "<PRE>failure</PRE>", but not "success" or "failure".Code:response.setContentType("text/plain"); final PrintWriter out; try { out = response.getWriter(); if (!success) { out.println("success"); } else { out.println("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?
Regards,
engram
-
1 Sep 2010 6:20 AM #2
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 #3
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 #4
set the contentype to
and it wont wrap it.Content-Type: text/html
I would return some json string from the servlet as that is easy to parse on the clientside.
-
1 Sep 2010 6:25 AM #5
-
1 Sep 2010 6:42 AM #6
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 #7
Yah,
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 #8
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
or can a RPC servlet handle file uploads. Hope my question is not funnyCode:formPanel.setAction(GWT.getModuleBaseURL() + "MyServlet");
Odili Charles Opute
Proudly Nigerian
Blog
Cotributions
Ext.ux.Image
Ext.ux.Wizard
Ext.plugin.ModalNotice
Ext.plugin.ComboLoader
Ext.ux.form.ScreenshotField
-
1 Sep 2010 11:07 AM #9
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 #10
Alright, I'll use another servlet, thanks.
Odili Charles Opute
Proudly Nigerian
Blog
Cotributions
Ext.ux.Image
Ext.ux.Wizard
Ext.plugin.ModalNotice
Ext.plugin.ComboLoader
Ext.ux.form.ScreenshotField
Similar Threads
-
Parsing response.responseXML in a browser-independent way
By kovtik in forum Ext 1.x: Help & DiscussionReplies: 3Last Post: 17 Feb 2012, 6:37 AM -
Need Help: Parsing XML from File vs Ajax Response
By csoon1 in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 23 Aug 2009, 7:22 AM -
parsing fileUploadField response
By chiru in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 20 Sep 2008, 6:59 PM -
Problem with response after file upload
By zurdophp in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 24 Jun 2008, 5:17 PM


Reply With Quote