Results 1 to 6 of 6
  1. #1
    keioGirl is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default Retrieving xml file from Web Server

    If I put my xml files in Apache HttpWebServer, how can I retrive those files in java. I think File API - new File(directoryPath).listFiles() cannot be used for web applications.
    And in DOM and xpath, I cannot retrive files which exists in other folders outside the Project folder. DOM cannot find it. Is there any way I can retrieve which exists in Appache HttpWebServer?

  2. #2
    w3user is offline Member
    Join Date
    Dec 2008
    Posts
    6
    Rep Power
    0

    Default

    Each of your xml file can be identified by its url.
    Use apache httpclient APIs to read the content of url.
    here's the tutorial link:
    hc.apache.org/httpclient-3.x/tutorial.html

    sample code:
    String url="your xml file url";
    GetMethod method = new GetMethod(url);
    int statusCode = client.executeMethod(method);
    byte[] responseBody = method.getResponseBody();
    String fileContent=new String(responseBody);

  3. #3
    keioGirl is offline Member
    Join Date
    Jul 2008
    Posts
    7
    Rep Power
    0

    Default

    Thanks.
    But the problem is I would like to get like 30 xml files simultaneously (example: by using some looping or like "..//localhost/8080/*.xml" though I know that *.xml doesn't work) without defining each specific url. How should I do that?

  4. #4
    2potatocakes is offline Member
    Join Date
    Sep 2008
    Posts
    43
    Rep Power
    0

    Default

    mmmm.. I'm also really curious as to how to do this. Does anyone know?

  5. #5
    mox8iro is offline Member
    Join Date
    Jan 2009
    Posts
    4
    Rep Power
    0

    Default

    hi,
    is there any naming convention of the xml files? do you know the number of files you want to get?
    if there is a specific pattern of naming the xml files maybe you will be able to retrieve them..

  6. #6
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Without providing any specifics on how to do this, I can tell you that a Web server will provide a directory listing *if* directory listing is authorized. So, the Web server has to be configured to allow listing. It will typically provide the list as an HTML page. You can test this from a browser by //http:url/ (no page specified). I would start by getting the Web server to provide a listing and then testing with a browser, to see what the output looks like.

    Web servers generally *do not* allow listing, to prevent people from seeing everything on the server, so if you don't control the server, you may not be able to get a listing.

    The other option is to have whoever is posting the files either use standard names, such as name-2009-01-16-x.xml, where the x is a sequence number 1,2,3,.., or have them place a list of names in an xml file on the server and update the file contents every time they post new files.

Similar Threads

  1. How to create file on server?
    By thevoice in forum New To Java
    Replies: 10
    Last Post: 08-12-2010, 06:06 PM
  2. Does any file in an FTP server ends up in an HTTP server?
    By islamfunny in forum CLDC and MIDP
    Replies: 4
    Last Post: 08-15-2008, 04:30 PM
  3. storing and retrieving a file as such
    By anil_manu in forum Advanced Java
    Replies: 0
    Last Post: 03-11-2008, 01:27 PM
  4. Checking of file was modified on the server
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-02-2008, 07:18 PM

Posting Permissions

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