Saturday, 15 January 2011

java.net.ProtocolException: Cannot write output after reading input -


I am trying to send the object to the Straight Action class by using the Object output stream, but one exception Java.net.ProtocolException : After reading the input the output can not be written.

I created a new instance of URLConnection to give a specific URL and tried to write an object in the URL to send the Stratus action class from the applet

I click the applet button button Calling this method to save

Public Save Design () {

  try {HttpURL Connection URL Connection = getServletConnection (Call Savelt Connection., Zero); // Pragma = no-cache; Faucet (urlConnection! = Null & amp; URL Connection. Getheadfield (.). ("Prague")! = Faucet) Return false; OutputStream Outstream = urlConnection.getOutputStream (); // Exception can be here ObjectOutputStream Object Outstream = New ObjectOutputStream (Outstream); Objectoutstream.writeObject ("abc"); Objectoutstream.flush (); Objectoutstream.close (); System.out.println ("write vctObjectDetails"); } Hold (malformedURLException exception) {exception Print straps (); } Catch (connect exception exception) {Exceptions Print straps (); } Hold (IOE exception exception) {exception Print straps (); } Hold (exception e) {e.printStackTrace (); }}   

But it does not work. Please give me some tips if someone knows how to handle this exception.

This is to do with the lifecycle of an HTTP request (which is the HttpURLConnection summary) - a Once the request has been sent, you can not modify it any more - if you have more data to send, then just create another one below what is happening when you getHeaderFields () (Response Header field), then the 'HTTPR Connection' sends the request and provides feedback.

I do not know what's in GetServletConnection (), but do not forget to read and read from the response, unless you finish writing the request.

No comments:

Post a Comment