Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use Servlet to read a webpage.

 
CC Huang
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Servlet, how can I read a webpage via internet into a string object. The webpage could be HTML or JSP.
Thanks,
 
Brian Glodde
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic