Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-16-2007, 09:49 PM   PM User | #1
bcarl314
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
bcarl314 will become famous soon enough
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.
bcarl314 is offline   Reply With Quote
Old 03-16-2007, 10:25 PM   PM User | #2
nikkiH
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
nikkiH is on a distinguished road
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
__________________

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/

Last edited by nikkiH; 03-16-2007 at 10:32 PM..
nikkiH is offline   Reply With Quote
Old 03-16-2007, 10:52 PM   PM User | #3
ess
Regular Coder

 
Join Date: Oct 2006
Location: United Kingdom
Posts: 865
Thanks: 7
Thanked 29 Times in 28 Posts
ess will become famous soon enough
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
ess is offline   Reply With Quote
Old 03-17-2007, 04:10 AM   PM User | #4
bcarl314
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
bcarl314 will become famous soon enough
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?
bcarl314 is offline   Reply With Quote
Old 03-17-2007, 08:08 AM   PM User | #5
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
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
Aradon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:19 PM.


Advertisement
Log in to turn off these ads.