The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

application-servlet communication URGENT!!!

Posted by Raging Bull on November 24, 2001 at 7:52 AM

People,
I need to upload a file from a workstation to a server. It should be asynchronous(ie, not based on user interaction).Hence, there is no form (html etc) involved. So i use a java client at the workstation and a servlet. Here is the code snippet.
//Client
URL url = new URL("http:m/c:port/servlet/FileuploadServlet");
URLConnection con = url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches (false);
con.setRequestProperty("Content-Type","multipart;application/octet-stream");
System.out.println("before opening output stream");
ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream()); //
System.out.println("after opening output stream");
out.writeObject("Success!");
out.flush();

//Servlet, in a method performTask() which is called by both //doget and dopost

ObjectInputStream oin = new ObjectInputStream(request.getInputStream()); //Even though the client is opening an output stream , the control never comes to this line
Object obj = oin.readObject();
System.out.println("Servlet: " + obj);

If the reverse happens, ie, servlet opens output stream and writes to client, then it works, but not in this case.
Any thoughts, anyone? It's very urgent.

Raging bull




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us