Home arrow static arrow Java Programming [Archive] - retrieve html page before parsing it
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - retrieve html page before parsing it
This topic has 1 reply on 1 page.

Posts:14
Registered: 7/2/04
retrieve html page before parsing it  
Jul 8, 2004 11:00 PM



 
Hi:

I'm trying to parse some query result returned from a web site. The following code returned me nothing, not even the html header and the pre-filled tags. When I replace "while(s2!=null){" with "a finite number of loops, say, 100, it worked. But when I increased the number of loops to 300 (actual page returns 327 lines of html code), it gave me nothing again. Could anybody please let me know what's wrong with my code or what should I do to retrieve an html page before I parse it? Thanks.

String s1 = new String();
String s2 = new String();
try{
URL u = new URL(url);
InputStream ins = u.openStream();
InputStreamReader isr = new InputStreamReader(ins);
BufferedReader br = new BufferedReader(isr);
while(s2!=null){
s2 = br.readLine();
s1 = s1.concat(s2);
}
//test part
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print(ServletUtilities.headWithTitle("Hello WWW") +
"<BODY>\n" + s1 +
"MANUALLY-ADDED" +
"</BODY></HTML>");
}

 

Posts:24,517
Registered: 98-02-27
Re: retrieve html page before parsing it  
Jul 9, 2004 7:54 AM (reply 1 of 1)



 
Here is a simple [url http://forum.java.sun.com/thread.jsp?forum=31&thread=285107]example[/url]. Don't use String.concat(..) method. Use a StringBuffer and convert it to a String once the entire file has been read.
 
This topic has 1 reply on 1 page.