Hello..
Thankx for the inputs.
A small problem still persists

I am getting a class cast exception during runtime(IE4) on the
statement
java.net.HttpURLConnection con
= (java.net.HttpURLConnection)url.openConnection();

What could be the reason.
Enviornment:NT4.0,JDK1.3


thankx.




Kevin Jones <[EMAIL PROTECTED]>@java.sun.com> on 01/19/2001 04:16:00
AM

Please respond to "A mailing list for discussion about Sun
      Microsystem's Java Servlet API Technology."
      <[EMAIL PROTECTED]>

Sent by:  "A mailing list for discussion about Sun Microsystem's Java
      Servlet API Technology." <[EMAIL PROTECTED]>


To:   [EMAIL PROTECTED]
cc:
Subject:  Re: urgent...


Not on my system -

I've just tried this and I get an exception.

If I call setDoOutput(true);
then write I get POST.

If I don't call setDoOutput(true) then it throws an exception.

Here's the code

java.net.URL url = new java.net.URL(urlString);
java.net.HttpURLConnection con =
(java.net.HttpURLConnection)url.openConnection();
//            con.setDoOutput(true);
//                con.setRequestMethod("POST");

java.io.OutputStreamWriter writer = new
java.io.OutputStreamWriter(con.getOutputStream());

and here's the exception

java.net.ProtocolException: cannot write to a URLConnection if
doOutput=false - call setDoOutput(true)
        at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown
Source)
        at Client.main(Client.java:22)
This is on W2K with jdk1.3

If i remove the comment on setDoOutput(true) then it works fine.

Try it,


Kevin Jones
DevelopMentor
www.develop.com

> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java
Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
Rob
> Griffin
> Sent: 18 January 2001 22:18
> To: [EMAIL PROTECTED]
> Subject: Re: urgent...
>
>
> > -----Original Message-----
> > From: A mailing list for discussion about Sun Microsystem's Java
Servlet
> > API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
Kevin
> > Jones
> > Sent: Friday, 19 January 2001 7:50
> > To: [EMAIL PROTECTED]
> > Subject: Re: urgent...
> >
> >
> > But only for POST or PUT, whcich this code isn't using
>
> Yes it is. Writing to the output stream of a URLConnection forces
> it to do a POST.
>
> >
> >
> > con.setRequestProperty("Content-Type","java-internal"+objs.getClas
> > s().getNam
> > e());
> >   ObjectOutputStream out = new
> ObjectOutputStream(con.getOutputStream());
> >   out.writeObject(objs);
> >
> > you should call con.setDoOutput(true);
> > or con.setRequestMethod("POST"); // JDK1.3 and above I think
> >
> > In fact the code shouldn't even execute.
> >
> > Thinking about it I assume there should be a call to
> > setDoOutput(true)  here
> > somewhere?
>
> ------------- from another post
>
> >> IE returns FileNotFoundException when it can't connect
> >
> >It's not IE that does this. URLConnection converts EVERY error
> code into a
> >FileNotFoundException
>
> Netscape throws an IOException in this case.
>
> >
> > Kevin Jones
> > DevelopMentor
> > www.develop.com
> >
>
> [snip]
>
> Rob Griffin
> Quest Software
>
> E-mail: [EMAIL PROTECTED]
> Web site: http://www.quest.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

___________________________________________________________________________
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