Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts

    Using JSP to open and read a remote XML file

    First post in the Java forum for me!

    I'm working on a project that uses JSP, unfortunately, I'm a PHP programmer by trade.

    Our project involves pulling in XML from an internal server, then parsing it. I'm not too worried about the parsing of the XML, but I can't seem to find any online resources on how to actually grab an XML file from a server via an HTTP request.

    All I really want is the JSP equivilant of PHP get_file_contents("http://192.168.1.1/server/xml_data.xml")

    I think Java uses file streams, network sockets, etc, but like I said, I'm not a Java programmer by nature.

    I've searched on Google for things like "JSP read remote file", and the like. The closest that I've come is something reading RSS feeds, but they usually have some proprietary or custom bean / tag library that I can't get installed.

    Any and all help is GREATLY appreciated.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Nah, not that hard.
    Someone might have a better bean example, but the basics look like this.
    http://www.exampledepot.com/egs/java...URL.html?l=rel
    Last edited by nikkiH; 03-16-2007 at 10:32 PM.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    865
    Thanks
    7
    Thanked 29 Times in 28 Posts
    The example given by nikkiH should do the trick.

    If you wish to explore more options, here is a good tutorial from Java World

    http://www.javaworld.com/jw-03-2000/...sj-jspxml.html


    Cheers,
    Ess

  • #4
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Quote Originally Posted by nikkiH View Post
    Nah, not that hard.
    Someone might have a better bean example, but the basics look like this.
    http://www.exampledepot.com/egs/java...URL.html?l=rel

    This looks like what I want, but what will I need for my import statements?

    String, Buffer? etc?

  • #5
    Regular Coder Aradon's Avatar
    Join Date
    Jun 2005
    Location
    USA
    Posts
    734
    Thanks
    0
    Thanked 20 Times in 19 Posts
    Code:
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.IOException;
    import java.net.URL;
    import java.net.MalformedURLException;
    Or if you weren't worried about what you imported..

    Code:
    import java.io.*;
    import java.net.*;
    But I'm more fond of the first one.
    "To iterate is human, to recurse divine." -L. Peter Deutsch


  •  

    Posting Permissions

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