• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

IO exception

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
 
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am confused as to why you are using ObjectInputStream if you are reading text. Why not try BufferedReader?
Barry
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic