1. #1
    Ext GWT Premium Member
    Join Date
    Aug 2010
    Posts
    37
    Vote Rating
    0
    engram is on a distinguished road

      0  

    Question 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:

    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());
       }
    }
    The result from the server (event.getResultHtml()) is, as the name implies, is HTML encoded although we write plain text at the server:

    Code:
    response.setContentType("text/plain");
    final PrintWriter out;
    try {
       out = response.getWriter();
       if (!success) {
          out.println("success");
       } else {
          out.println("failure");
       }
    }
    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?

    Regards,
    engram

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Only FireFox wraps it into pre tags if you send the wrong contenttype from the server. What contenttype do you set on your server?

  3. #3
    Ext GWT Premium Member
    Join Date
    Aug 2010
    Posts
    37
    Vote Rating
    0
    engram is on a distinguished road

      0  

    Default


    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".

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    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.

  5. #5

  6. #6
    Ext GWT Premium Member
    Join Date
    Aug 2010
    Posts
    37
    Vote Rating
    0
    engram is on a distinguished road

      0  

    Default


    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.

  7. #7
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Yah,

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

  8. #8
    Sencha User chalu's Avatar
    Join Date
    Feb 2008
    Location
    Benin City, Nigeria
    Posts
    480
    Vote Rating
    1
    chalu is on a distinguished road

      0  

    Default


    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
    Code:
    formPanel.setAction(GWT.getModuleBaseURL() + "MyServlet");
    or can a RPC servlet handle file uploads. Hope my question is not funny

  9. #9
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,966
    Vote Rating
    130
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    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.

  10. #10
    Sencha User chalu's Avatar
    Join Date
    Feb 2008
    Location
    Benin City, Nigeria
    Posts
    480
    Vote Rating
    1
    chalu is on a distinguished road

      0  

    Default


    Alright, I'll use another servlet, thanks.

Similar Threads

  1. Parsing response.responseXML in a browser-independent way
    By kovtik in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 17 Feb 2012, 6:37 AM
  2. Need Help: Parsing XML from File vs Ajax Response
    By csoon1 in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 23 Aug 2009, 7:22 AM
  3. parsing fileUploadField response
    By chiru in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 20 Sep 2008, 6:59 PM
  4. Problem with response after file upload
    By zurdophp in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 24 Jun 2008, 5:17 PM

Thread Participants: 2

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar