Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

IO exception  RSS feed

 
Charlie Boss
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i'm using the following code open a connection to my servlet from my applet so i can retrieve some database info. I works fine at first but sometimes i get this error:
"java.io.StreamCorruptedException: invalid stream header"
please help.. i do not know why its so tempremental and i'm not well versed in stream headers.. how can i set the stream header to accept text from servlet. Thats all i'm transmitting, text.
Examples of what i'm getting from my servlet are:
value1|value2|value3| => works fine
key1=value1|key2=value2|key3=value3| => error occurs
=====
try{
URL servletURL = new URL(servletLocation);
URLConnection servletConnection = servletURL.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
servletConnection.setRequestProperty("Content-Type","application/octet-stream");
inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
resultdata = (String)inputFromServlet.readObject();
inputFromServlet.close();
}

 
jack welsh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even I am facing a similar problem, Any help would be greatly appreciated.
Thanks in Advance,
Jack
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you seeing the exception - on client or server?
How are you writing to the output stream in the servlet (ObjectOutputStream)?
When you see the exception, what was the response status code - HttpURLConnection.getResponseCode() ? Was it 200 (OK) or some error code (404, 501, 503)?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!