Code example for URLConnection

Methods: getInputStream, getOutputStream, setDefaultUseCaches, setDoInput, setDoOutput, setRequestProperty, setUseCaches

0
         try{ 
          URL servlet = new URL(_frame.getCodeBase().toString()+ "ac");
        URLConnection servletConnection =servlet.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/x-www-form-urlencoded");
 
 
// send the student object to the servlet using serialization 
       ObjectOutputStream  outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
 
// serialize the object 
 
        outputToServlet.writeObject(data);
         
 
        outputToServlet.flush();
        outputToServlet.close();
 
         InputStream inputStream = servletConnection.getInputStream();
 
         ch = (char)inputStream.read();
         //  System.out.println("************ message from servlet: " + ch); 
        inputStream.close();