> I have the following jsp pages on different tomcat web servers:
>
[quoted text clipped - 8 lines]
>
> Thierry
You cannot read the "content" of the JSPs, but you can, however, read
the "output" of those JSPs as if your code is a browser, which is what
I think you meant by User Agent. You can either use Apache's
HttpClient API (my preference), or roll your own using the
java.net.URLConnection. You will find plenty of examples if you google
these two APIs.
It is not as straightforward as LWP :)
-cheers,
Manish
Thierry Lam - 25 Jul 2007 19:47 GMT
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.
Daniel Pitts - 25 Jul 2007 20:43 GMT
> 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.
Something along the lines of:
new URL("http://serverone/bugs/download.jsp?
num=1234&file=Jul25.txt").getContent();
<http://java.sun.com/j2se/1.4.2/docs/api/java/net/URL.html>
At the very worst case, you will need to call getContentAsStream() and
then read in the content. although getContent() might to what you
need.
shakah - 25 Jul 2007 20:54 GMT
> 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 ;
}
Daniel Pitts - 25 Jul 2007 20:45 GMT
> > I have the following jsp pages on different tomcat web servers:
>
[quoted text clipped - 17 lines]
>
> It is not as straightforward as LWP :)
Actually, it is very straightforward. You don't need to mess with
URLConnection for retreiving the content of specific URLs, new
URL(urlString).getContent() should do the trick.
> -cheers,
> Manish
Daniel.
>Is there a way in java to read the content of those urls?
See http://mindprod.com/products.html#HTTP
http://mindprod.com/jgloss/products.html#FILETRANSFER (use the
download utility)
see http://mindprod.com/applet/fileio.html for sample code to HTTP
GET.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com