Search code examples
javatomcatobjectinputstream

Java web start applet cannot connect with localhost servlet


I can't find problem similar to my problem with jws so I write here.

I hava java applet that I try to run with jws technology. In applet I have method that send a object to servlet and try to getInputStream. Unfortunetly I have a exception:

java.io.StreamCorruptedException: invalid stream header: 3C21444F at java.io.ObjectInputStream.readStreamHeader at java.io.ObjectInputStream.

method example:

  String url = "http://localhost/servlet/myServlet";
  URL servletUrl = new URL(url);

  URLConnection urlConn = servletUrl.openConnection();
  urlConn.setDoOutput(true);
  urlConn.setDoInput(true);
  urlConn.setUseCaches(false);
  urlConn.setRequestProperty("Content-Type", "application/x-java-serialized-object");

  ObjectOutputStream oos = new ObjectOutputStream(urlConn.getOutputStream());
  oos.writeObject(myobject);
  oos.close();

  ObjectInputStream ois = new ObjectInputStream(urlConn.getInputStream()); //StreamCorruptedException
  Object obj = ois.readObject();
  oIS.close();

I have no ide why. Please type your ideas in post's.

from oracle's forum: An object serialization stream should not start with 3C21444F, which is ASCII for

<!DO

This means that the server/servlet, for some reason, does not send you what you think it should. It's rather the beginning of an XML document, perhaps an error page.


Solution

  • It was due the servlet authorization system .