> according to the spec if there is any I/O error when you try
> to construct an URL object, then there it would throw an I/O error only
but
> here it throws an UNKNOWNHOSTEXCEPTION error.
There are three classes in java.net which are tightly related. These are the
URL, URLConnection & URLStreamHandler. Even though you may be using only the
URL class all these three classes come into play when you try to create a
connection. For more details on what is the relation you can look up the API
docs.
Now the first step is the Creation of the URL. This throws not an
IOException but a subclass of it MalformedURLException. This exception
indicates that the URL that you have specified in the constructor is not as
per the semantics of a URL or the protocol specified is not valid i.e the
specified URL is not valid.
You will not get an UnknownHostException here because the URL has not even
tried to create a connection the specified url even if the specified url is
valid.
> But when i just
> construct an URL and try to read the protocol and portnumber it works like
> charm, this UNKNOWNHOSTEXCEPTION comes only for when i try to open an I/O
> input.
Only when you try to open an I/O stream on this url, an attempt is made to
connect to the specified URL. Then a lookup is performed on the DNS to get
the IP and connection is initiated (through a subclass of URLStreamHander).
It is at this point that you get an exception *UnknownHostException*.
Although the specified exception is IOException, UnknownHostException can
also be thrown as this is a subclass of IOException.
I hope this helps with some of ur doubts.
Regds,
Gokul
> >From: Duane Morse <[EMAIL PROTECTED]>
> >Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> > Servlet API Technology." <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >Subject: Re: HANDLER THREAD PROBLEM: java.io.IOException: Socket Closed
> >Date: Tue, 14 Nov 2000 11:09:46 -0700
> >
> >From my experience with sockets, the input stream and output stream are
> >probably
> >tied to the same socket, and closing the input closes the output too.
> >Then,
> >when
> >you close the output yourself, you get the exception.
> >
> >Solution -- let the base class close the streams.
> >
> >Duane Morse, Eldorado Computing Inc., Phoenix AZ
> >
> >
> >-----Original Message-----
> >From: James Knowles [mailto:[EMAIL PROTECTED]]
> >Sent: Tuesday, November 14, 2000 9:48 AM
> >To: [EMAIL PROTECTED]
> >Subject: Re: HANDLER THREAD PROBLEM: java.io.IOException: Socket Closed
> >
> >
> >I am also getting this... does anybody know how to catch this
exception...
> >
> >This is my code that give this error on the console ... ( I am on NT as
> >well
> >(please forgive me... ))
> >
> >import java.io.*;
> >import java.net.*;
> >import java.text.*;
> >import java.util.*;
> >import javax.servlet.*;
> >import javax.servlet.http.*;
> >
> >
> >public class readand extends HttpServlet {
> >
> >
> >
> >public void doGet(HttpServletRequest request,HttpServletResponse
response)
> >throws IOException, ServletException
> > {
> >
> > response.setContentType("text/html");
> > PrintWriter out = response.getWriter();
> >try {
> > URL url = new URL("http://www.laserrec.co.uk/Default.asp");
> > BufferedReader in = new BufferedReader(new
> >InputStreamReader(url.openStream()));
> >
> > int countit = -1;
> > String str;
> > while ((str = in.readLine()) != null) {
> > out.println(str + "\n");
> > }
> > in.close();
> > } catch (MalformedURLException e) {
> > }
> > catch (IOException e) {
> > out.println("<br>The webserver is down");
> > out.println(e);
> > }
> >
> > }
> >}
> >
> >When it returns the page correctly I get all of the java.io.IOExceptions
> >even though I thought I would have caught them all with catch
(IOException
> >e)
> >
> >Hope this helps explain a bit more of the problem ...
> >
> >James
> >
> >----- Original Message -----
> >From: "[Andrew Fairburn]" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Sent: Tuesday, November 14, 2000 3:57 PM
> >Subject: HANDLER THREAD PROBLEM: java.io.IOException: Socket Closed
> >
> >
> > > Hello,
> > > I'm using jswdk-1.0.1 on NT and keep getting this exception. Does
anyone
> > > know what is causing this - or even suggest something. I've searched
the
> > > archives/ and the web but have been unable to resolve it. Thanks,
> > > Andy
> > >
> > >
> > > HANDLER THREAD PROBLEM: java.io.IOException: Socket Closed
> > > java.io.IOException: Socket Closed
> > > at
> >java.net.PlainSocketImpl.getInputStream(PlainSocketImpl.java:421)
> > > at java.net.Socket$1.run(Socket.java:335)
> > > at java.security.AccessController.doPrivileged(Native Method)
> > > at java.net.Socket.getInputStream(Socket.java:332)
> > > at
> > > com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)
> > >
> > >
> > >
> > > Andrew Fairburn
> > > Vodafone Multimedia Ltd
> > > Tel: 01635-685841
> > >
> > >
>
>___________________________________________________________________________
> > > 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
> >
>
>___________________________________________________________________________
> >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
>
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
> Share information about yourself, create your own public profile at
> http://profiles.msn.com.
>
>
___________________________________________________________________________
> 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