www.webdeveloper.com
Results 1 to 4 of 4

Thread: getting http response from java servlet

  1. #1
    Join Date
    Jul 2003
    Posts
    2

    getting http response from java servlet

    Is it posible to take http post response from some java servlet into some variable in java script let's say some string?
    When I do http post request servlet returns some xml as a response and I would like to take that xml into some variable so that I can parse it with java script and then use that data.
    Does any one has some ideas?
    Thank.

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    What you can do is in your servlet get the string value for that XML object..

    root.toString() or something
    and then create a javascript string with that..

    "var xmlStr = '"+root.toString()+"'";

    something along the lines you need to try..
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Jul 2003
    Posts
    2
    Thank's for your quick answer.
    This is exatcly what I'm trying to do.
    I do http post from DHTML page on some URL where my servlet is. My servlet then does what it has to be done and
    give back response witch is an String xmlstr containing XML with
    PrintWriter out=response.getWriter();
    out.println(xmlstr);
    I would like to catch that xmlstr in my DHTML page in some
    java script variable so that I can parse it in java script or that
    I can generate a tree with nodes. I've tried it with loading response into layer but I couldn't get xml in it. Do you now of
    a way to catch this xmlstr response into some java script variable on the same DHTML page for witch http post request
    was done.

    Thanks and best regards.

  4. #4
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119

    PrintWriter out=response.getWriter();
    out.println(xmlstr);


    Code above will not pust xml string in a js variable..it will just dump all the data to the page.
    you need to do something like this.
    out.println("<script>");
    out.println("var xmlStr = '"+xmlstr);
    out.println("</script>");

    The above should do what you are looking for
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles