try this it must work ...try to read it as bytes..code included trythis
manu
import java.net.*;
import java.io.*;
public  class javai
{
        static int i=0;
public static void main(String arg[])
{


try{

URL weatherurl1=new
URL("http://www.wbc.com/wbc/member_list_company.asp?mode=show_new&letter=a")
;
System.out.println("SUCESS.....");
System.out.println("Reading file1");


saveImage(weatherurl1);
i=1;
//System.out.println("hello2");
i=0;
}
catch(MalformedURLException e)
{
        System.err.println("URL not found try later");
}
}


public static void saveImage(URL u)
{
int buff=1;
try
{
URLConnection urlconnect=u.openConnection();
String content=urlconnect.getContentType();
int clength=1;
if(i==0)
{
         clength=4624;
}
else
{

 clength=urlconnect.getContentLength();
}
//System.out.println(clength);
if(content.startsWith("text/")||clength==-1)
{//System.err.println("There is error in content..try later");
//return;
}
InputStream Image=urlconnect.getInputStream();
byte[] b=new byte[clength];
int bytesread=0;
int offset=0;
while(bytesread>=0 || bytesread==clength)
{
        bytesread=Image.read(b,offset,buff);

if(bytesread==-1)break;
offset+=bytesread;
//System.out.println(offset);
}
//System.out.println(offset);
if(offset!=clength)
System.err.println("Error");
/* mor error mess*/
//System.out.println("offset");
String weatherfile=u.getFile();
weatherfile=weatherfile.substring(weatherfile.lastIndexOf('/'));
System.out.println(weatherfile+" Completed");
FileOutputStream fout=new FileOutputStream(weatherfile);
fout.write(b);
}
catch(Exception e)
{
System.err.println(e);
}
return;
}
}

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
fumitada
Sent: Tuesday, November 21, 2000 1:09 AM
To: [EMAIL PROTECTED]
Subject: Anyone can solve my problem ?


I made a WBC class (below) that retrieve a web page.
The class constructer takes URL of desired page.
It worked well until I tried this page.
(http://www.wbc.com/wbc/member_list_company.asp?mode=show_new&letter=a)

The server gave me "request cannot be processed if object is closed..."
like that error, and I couldn't get whole HTML code of the page.
I guessed that Buffer was kinda small, so I tried 1MB as a
buffer(BufferedReader(...,1000000). BUT It Still doesn't work.

Anybody can help me out ?

Anyway, Please try my code and the URL.

import java.net.*;
import java.sql.*;
import sun.misc.*;
import java.io.*;
import java.util.*;
import java.text.*;

public class WBC{

String line = null;
String cat_name = null;
Connection con = null;
Statement stmt = null;
protected String host,file;
protected int port;
protected URL url;
protected Writer writer;
protected BufferedReader reader;
//public HashSet hashset;
String count_offers = null;
String next = null;
int count = 0;

public WBC(String url) throws MalformedURLException {
this.cat_name = cat_name;
this.url = new URL(url);
}

public void set_url(String url) throws
MalformedURLException {
this.url = new URL(url);
}
protected void get(){
String title="EMPTY";

try{
dissect();
connect();
fetch();
}catch(Exception e){
}

}

protected void dissect() throws MalformedURLException {

host = url.getHost();
port = url.getPort();

if(port == -1)
port = 80;

file = url.getFile();
}

protected void connect() throws IOException{
Socket socket = new Socket(host,port);

OutputStream out = socket.getOutputStream();
writer = new OutputStreamWriter(out,"latin1");

InputStream in = socket.getInputStream();
Reader reader = new InputStreamReader
(in,"latin1");
this.reader = new BufferedReader
(reader,1000000);
}

protected void fetch() throws IOException{
writer.write("GET " + file + " HTTP/1.0
\r\n\n");
writer.flush();

String input;

while( (input = reader.readLine() ) != null ){
System.out.println(input);

}

}

public static void main(String args[]) throws MalformedURLException,
IOException{



WBC wbc = new WBC
("http://www.wbc.com/wbc/member_list_company.asp?mode=show_new&letter=a");
wbc.get();


}
}

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to