srinivas wrote:
> import java.net.*;
> import java.io.*;
>
> public class four
> {
> static char c;
> public static void main(String[] args)
> {
> int x = 0;
> try
> {
> URL url = new
> URL("http://164.164.61.118:8080/servlet/test");
> URLConnection urlc = url.openConnection();
>>> Add: urlc.setDoOutput(true);
>
> urlc.connect();
> System.out.println("Finished startinmg");
> OutputStreamWriter os = new
> OutputStreamWriter(urlc.getOutputStream());
> System.out.println("Inside stuff");
> os.write('s');
> os.close();
> System.out.println("finished writing");
> InputStreamReader is = new
> InputStreamReader(url.openStream());
> while ( x != -1)
> {
> System.out.println("The str is " + is.read());
> }
> is.close();
> }
> catch(MalformedURLException mue)
> {
> }
> catch(IOException ioe)
> {}
> }
> }
>
> Experts pls consider thiscode i am trying to write soem data toi a servlet and
> getting back them can i able to write to a servlet thro a url connection???
>
> Please clarify.
>
As indicated above, you have to call setDoOutput() before calling connect() if
you intend to write to a URLConnection. This is covered lightly in the API docs,
and more thorougly in the Network Programming trails in the Java Language
Tutorial:
http://java.sun.com/docs/books/tutorial
In addition, I would recommend putting in some logging in your exception catching
loops, so that you can at least find out what happened -- otherwise, your servlet
is just going to return silently. Perhaps something like:
catch (MalformedURLException mue) {
log("Got a MalformedURLException", mue);
} catch (IOException ioe) {
log("Got an IOException", ioe);
}
which will dump the error message and a stack trace into your servlet log, so you
can find out what went wrong.
>
> Thanks
> Srini
>
Craig McClanahan
___________________________________________________________________________
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