Hi, all.............
Now i used ObjectInputStream to read the data from servlet.
But it can't work too.
The segment program file included in File.txt.
 
Thanks
 
Regards ,
Yulyanto
This is the segment program to read the data from servlet :

void displayReport() {
  try {
   System.out.println("Attempting to connect to 
http://yulyanto:8080/servlet/Applet2Servlet");
   java.net.URL url = new java.net.URL("http://yulyanto:8080/servlet/Applet2Servlet");
   java.net.URLConnection con = url.openConnection();
   con.setUseCaches(false);
   con.setDoOutput(true);
   con.setDoInput(true);
   ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
   DataOutputStream out = new DataOutputStream(byteOut);
   System.out.println("Writing test data");
   
   out.writeByte(5);
   out.writeUTF(Applet1.tperusahaan);
   out.writeUTF(Applet1.tregion);
   out.writeUTF(Applet1.tunit);
   out.writeUTF(Applet1.tsubunit);
   out.writeUTF(Applet1.tperiode1);
   out.writeUTF(Applet1.tperiode2);
   out.writeUTF(Applet1.tchickin1);
   out.writeUTF(Applet1.tchickin2);
   
   out.flush();
   byte buf[] = byteOut.toByteArray();
   con.setRequestProperty("Content-type","application/octet-stream");
   con.setRequestProperty("Content-length",""+ buf.length);
   DataOutputStream dataOut =
    new DataOutputStream(con.getOutputStream());
   dataOut.write(buf);
   
//   System.out.println("Trying to flush the data ");
   
   dataOut.flush();
   dataOut.close();
   
   System.out.println("Reading response...");
   ObjectInputStream inputFromServlet = null;
   inputFromServlet = new ObjectInputStream(con.getInputStream());
   System.out.println("Completing reading data ... ");
   Vector theInputFromServlet = (Vector) inputFromServlet.readObject();
   System.out.println(theInputFromServlet.toString());
   inputFromServlet.close();
         
   Enumeration enum = theInputFromServlet.elements();
     
   ResultData aData = null;
   String farm = null;
   String flock = null;
   String datein = null;

   while (enum.hasMoreElements())
   {
      aData = (ResultData) enum.nextElement();
       
      farm = aData.getFarm();
      flock = aData.getFlock();
      datein = aData.getDateIn();
            
      System.out.println(farm);
   }
     
   System.out.println("Closing response...");
  }
  catch (Exception ex) {
      ex.printStackTrace();
  }     
 }

and this is the segment program to send the data to my applet :

 public void service(HttpServletRequest req, HttpServletResponse resp)
 throws ServletException, IOException
 {
     DataInputStream in = 
      new DataInputStream(req.getInputStream());
      
  resp.setContentType("application/octet-stream");
  
  byte byteValue = in.readByte();
        
   String tPerusahaan = in.readUTF();
   String tRegion = in.readUTF();
   String tUnit = in.readUTF();
   String tSubUnit = in.readUTF();
   String tPeriode1 = in.readUTF();
   String tPeriode2 = in.readUTF();
   String tChickIn1 = in.readUTF();
   String tChickIn2 = in.readUTF();
      
   Vector outData = new Vector();
     try {
       Statement stmt1 = conConnection.createStatement();
       String query = 
           "select distinct a.kode_perusahaan, b.kode_region, c.kode_unit, 
d.kode_subunit "+
           "from tblperusahaan a, tblregion b, tblunit c, tblsubunit d "+
           "where a.nama_perusahaan = '"+tPerusahaan+"' and "+
           "b.nama_region = '"+tRegion+"' and "+
           "c.nama_unit = '"+tUnit+"' and "+
           "d.nama_subunit = '"+tSubUnit+"'";
       log(query);
       ResultSet rs1 = stmt1.executeQuery(query);
       rs1.next();
       String tkodeperusahaan = rs1.getString("kode_perusahaan");
       String tkoderegion = rs1.getString("kode_region");
       String tkodeunit = rs1.getString("kode_unit");
       String tkodesubunit = rs1.getString("kode_subunit");
             String tlokkey = tkodeperusahaan.trim()+tkoderegion.trim()+
                       tkodeunit.trim()+tkodesubunit.trim()+"%";
       rs1.close();
       stmt1.close();
       
       Statement stmt = conConnection.createStatement();
       query =
                 "select cmhfarm, cmhflock, dmhdatein, cmhstrain, cmhgrade, "+
                 "nmhjml_in, nmslastpop, (dmhdatein+nmhumurakh-1) as tglakhirmg, 
nmhumurakh,   
                  nmhtpanen, nmhtberat, nmhumur, "+
                 "nmsfcr1, nmsfcr2, nmsfcr3, nmsfcr4, nmsfcr5, nmsfcr6, nmsfcr7, 
nmsfcr8, 
                  nmsfcr9, nmsfcr10, "+
                 "nmsdpl1, nmsdpl2, nmsdpl3, nmsdpl4, nmsdpl5, nmsdpl6, nmsdpl7, 
nmsdpl8, 
                  nmsdpl9, nmsdpl10, "+
                 "nmswhrate1, nmswhrate2, nmswhrate3, nmswhrate4, nmswhrate5, 
nmswhrate6, 
                  nmswhrate7, nmswhrate8, nmswhrate9, nmswhrate10, "+
                 "nmhfcr, nmhdepl, nmhbw, nmhip, "+
                 "cmhppl, nmhpakan, nmhumrekor, cmhnipkey "+
                 "from mrtrxhd, mrstat "+
                 "where "+
                 "cmhnipkey like '"+tlokkey+"' and "+
                 "between((dmhdatein+nmhumur),{"+tPeriode1+"},{"+tPeriode2+"}) and 
                  lmhposted=.T. and "+
                 "cmh_pk=cms_mhfk order by cmhppl"; 

       log(query);
       ResultSet rs = stmt.executeQuery(query);
       ResultData data = null;
       int count=1;
       
       ResultData aData = null;

       while (rs.next()) {
         log(String.valueOf(count));
         aData = new ResultData(rs);
         outData.addElement(aData);
                
         log("Complete reading row : "+count);count++;
       }

       rs.close();
       stmt.close();
       log("Closing statement ");
      }
      catch (SQLException ex) {
       log(ex.getMessage());   
      }
      log("Preparing for sending data .... ");
      ObjectOutputStream outputToApplet;
      outputToApplet = new ObjectOutputStream(resp.getOutputStream());
      log("Sending result vector to applet...");
      outputToApplet.writeObject(outData);
      outputToApplet.flush();
            
      outputToApplet.close();
      log("Data transmission complete.");
      
 }

and I got this error message in my Java Console :

java.io.IOException: InternetReadFile
 at com/ms/net/wininet/WininetInputStream.read
 at com/ms/net/wininet/WininetInputStream.read
 at java/io/ObjectInputStream.read
 at java/io/DataInputStream.readUnsignedByte
 at java/io/DataInputStream.readUTF
 at java/io/DataInputStream.readUTF
 at java/io/ObjectInputStream.readUTF
 at java/io/ObjectInputStream.readString
 at java/io/ObjectInputStream.checkSpecialCases
 at java/io/ObjectInputStream.readObject
 at com/ms/!!!Internal_Class_1.DefaultReadMethod
 at java/io/ObjectInputStream.invokeDefaultReadObject
 at java/io/ObjectInputStream.defaultReadObject
 at java/io/ObjectInputStream.readNewObject
 at java/io/ObjectInputStream.readObject
 at java/io/ObjectInputStream.readObjectArray
 at java/io/ObjectInputStream.readArrayValues
 at java/io/ObjectInputStream.readArray
 at java/io/ObjectInputStream.checkSpecialCases
 at java/io/ObjectInputStream.readObject
 at com/ms/!!!Internal_Class_0.DefaultReadMethod
 at java/io/ObjectInputStream.invokeDefaultReadObject
 at java/io/ObjectInputStream.defaultReadObject
 at java/io/ObjectInputStream.readNewObject
 at java/io/ObjectInputStream.readObject
 at Applet2.displayReport
 at Applet2.init
 at com/ms/applet/AppletPanel.securedCall0
 at com/ms/applet/AppletPanel.securedCall
 at com/ms/applet/AppletPanel.processSentEvent
 at com/ms/applet/AppletPanel.processSentEvent
 at com/ms/applet/AppletPanel.run
 at java/lang/Thread.run

Reply via email to