Re: How do you read the content of internal web pages?
On Jul 25, 2:47 pm, Thierry Lam <lamthie...@gmail.com> wrote:
Yes, it's the content of the jsp pages that I want to read. I usually
post on the newsgroup when I can't find anything from googling. If
anyone got any small sample working codes, let me know.
Check out java.net.URLConnection, its getContent() method might be all
you need.
Below is a quick-and-dirty example of another way to use
URLConnection, though you'll have to catch the Exceptions to get it to
compile cleanly:
public StringBuffer fetch(String sURL) {
StringBuffer sbResponse = new StringBuffer(8192) ;
java.net.URL url = new java.net.URL(sURL) ;
java.net.URLConnection urlc = url.openConnection() ;
urlc.setDoInput(true) ;
urlc.setUseCaches(false) ;
java.io.InputStream is = urlc.getInputStream() ;
int nContentLength = urlc.getContentLength() ;
byte [] ab = new byte[nContentLength] ;
int nRead=0 ;
while(nRead < nContentLength) {
nRead += is.read(ab, nRead, nContentLength - nRead) ;
}
sbResponse.append(new String(ab, "utf-8")) ;
is.close();
is = null ;
((java.net.HttpURLConnection) urlc).disconnect() ;
urlc = null ;
return sbResponse ;
}