Hey!
I believe you are not setting up your POST message correctly.
See comment below.
Sans adieu,
Danny Rubis
Nelson wrote:
> Hi,
>
> I keep getting the exception "java.io.StreamCorruptedException: InputStream
> does not contain a serialized object", but I really don't understand why
> this is happening. It seems to be raising this exception even before i do a
> in.readObject() ! But why??
>
> Below is the output from the servlet console:
>
> JSDK WebServer Version 2.1
> Loaded configuration from file:C:\test-server/default.cfg
> endpoint created: :8080
> com.sun.web.core.InvokerServlet: init
> LoginServlet: init
> com.sun.web.core.DefaultServlet: init
>
> This is the output from the java plugin console
>
> Url passed in is: http://localhost:8080/servlet/LoginServlet/
> sent objects!
>
> io exception: java.io.StreamCorruptedException: InputStream does not
> contain a serialized object
> java.io.StreamCorruptedException: InputStream does not contain a serialized
> object
> at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
> at java.io.ObjectInputStream.<init>(Unknown Source)
> at TMSApplet.postObjects(TMSApplet.java:66)
> at LoginApplet$1.actionPerformed(LoginApplet.java:54)
> at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
> at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Unknown
> Source)
> at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> at javax.swing.plaf.basic.BasicButtonListener.mouseR ....(etc)
>
> This is the relevant code snippet from LoginApplet
>
> URL url = constructURL(getCodeBase(), loginServlet);
>
> String userID = useridTextField.getText();
> String password = new String(passwordPasswordField.getPassword());
> //String password = passwordPasswordField.getText();
> Serializable objects[] = {userID, password};
> ObjectInputStream in = postObjects(url, objects);
>
> //will always get a string indicating the result
> String result = (String)in.readObject();
> System.err.println("Got response: " + result.toString());
>
> This is the function "postObjects" in TMSApplet (which is an abstract class
> that LoginApplet inherits from)
>
> protected ObjectInputStream postObjects(URL url, Serializable objects[])
> throws Exception
> {
> System.err.println("Url passed in is: " + url );
> URLConnection connection = url.openConnection();
> connection.setDoInput(true);
> connection.setDoOutput(true);
> connection.setUseCaches(false);
>
> connection.setRequestProperty("Content-Type",
> "application/x-www-form-urlencoded");
>
Check this Content-Type.
You are saying that your request is one type and sending another.
Try something similar to this:
// Set the content type to be java-internal/classname
con.setRequestProperty("Content-Type",
"java-internal/" + obj.getClass().getName());
>
> ObjectOutputStream out = new
> ObjectOutputStream(connection.getOutputStream());
> int numberOfObjects = objects.length;
> for(int i = 0; i < numberOfObjects; i++)
> {
> out.writeObject(objects[i]);
> }
> out.flush();
> out.close();
> System.err.println("sent objects!");
> ObjectInputStream in = new
> ObjectInputStream(connection.getInputStream()); //Line 66!!!
> System.err.println("input stream created");
> return in;
> }
>
> In the exception it says it's raised at line 66, but why?? You notice that
> the objects were sent, because the debugging code was printed to the applet
> console "sent objects". But the applet has not done a readObject() yet..so
> why the exception? How can I stop this happening. Also the servlet should
> print out a line to the servlet console telling me that it received the two
> String's i sent - but that didn't happen either. Maybe the objects didn't
> get sent, maybe the connection wasn;t made in the first place.. but
> strange..why not? http://localhost:8080/servlet/LoginServlet/ certainly
> does exist.
>
> Can anyone please help me, please?
>
> Regards,
> Nelson
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html