// Listing 2 // // Applet client-side code to send a student object // to a servlet in a serialized fashion. // // A POST method is sent to the servlet. // URL studentDBservlet = new URL( webServerStr ); URLConnection servletConnection = studentDBservlet.openConnection(); // inform the connection that we will send output and accept input servletConnection.setDoInput(true); servletConnection.setDoOutput(true); // Don't use a cached version of URL connection. servletConnection.setUseCaches (false); servletConnection.setDefaultUseCaches (false); // Specify the content type that we will send binary data servletConnection.setRequestProperty ("Content-Type", "application/octet-stream"); // send the student object to the servlet using serialization outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream()); // serialize the object outputToServlet.writeObject(theStudent); outputToServlet.flush(); outputToServlet.close();