You need to reverse the order of the sendCustomerToServlet() and
connect() calls.

At the point you are logging "Connected", the connection has actually
only been "Opened".  After opening, you can set the various properties
that determine how the connection will take place, then call connect()
to actually create the connection, after which you can send your
serialized object.  I presume you also have code after this to process
the response from the servlet.

See the JavaDoc for class URLConnection for more info.  There is also a
trail in the Java Language Tutorial on using URLConnection to interact
with a server.  (http://java.sun.com/docs/books/tutorial)

Craig McClanahan


Ragna-Lena&Dan wrote:

>  I try to send a number of userdefined strings as a serialized object
> froman applet to a servlet (I use Jigsaw 2.0.2 as a server on my
> localhost). This is my code for sending the object from the
> applet:           log("Connecting to servlet...");
>            URL StakoDBservlet = new URL( urlStr);
>            URLConnection servletConnection =
> StakoDBservlet.openConnection();
>            log("Connected");
>            servletConnection.setDoInput(true);
>            servletConnection.setDoOutput(true);
>            servletConnection.setUseCaches (false);
>            servletConnection.setRequestProperty("Content-Type",
> "application/octet-stream");
>            sendCustomerToServlet(servletConnection, theCustomer);
>            servletConnection.connect();
>  The method sendCustomerToServlet(servletConnection, theCustomer);
>  // theCustomer is the serialized object looks like this:protected
> void sendCustomerToServlet(URLConnection servletConnection, StakoReg
> theCustomer)
>     {
>         ObjectOutputStream outputToServlet = null;         try
>         {
>
>          log("Sending the customer to the servlet...");
>          outputToServlet = new
> ObjectOutputStream(servletConnection.getOutputStream());
> outputToServlet.writeObject(theCustomer);
> outputToServlet.flush();
>          outputToServlet.close();
>          log("Complete.");
>         }
>         catch (IOException e)
>         {
>           log(e.toString());
>         }
>     } I log "Complete" but then I get a java.net socketExceptionwith
> the message 'Unexpected end of file from server'. Please advise.-dan

___________________________________________________________________________
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

Reply via email to