wood burning stoves
The moose likes Servlets and the fly likes Use Servlet to read a webpage. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Use Servlet to read a webpage. " Watch "Use Servlet to read a webpage. " New topic

Use Servlet to read a webpage.

CC Huang

Joined: Jun 27, 2002
Posts: 1
Using Servlet, how can I read a webpage via internet into a string object. The webpage could be HTML or JSP.
Brian Glodde
Ranch Hand

Joined: Jun 27, 2001
Posts: 171
You'll be using a URLConnection object, then use a DataInputStream to retrieve the output of the page (if it's a server side script). You could then store it in a String or a File structure.
Hope that helps!
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Note that if you use a url starting "http://" you automatically get a HttpURLConnection so look in those docs for the methods that let you set request headers etc.
I agree. Here's the link: http://aspose.com/file-tools
subject: Use Servlet to read a webpage.
It's not a secret anymore!