dcsimg
Error reading serialized objects throws!_NEWLINE_!java.io.StreamCorruptedException: Type code out of range, is 0 0
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Kulvinder_Saggu
Posted On:   Monday, March 25, 2002 01:23 PM

I wish to send two object consecutively, the first is a large nerual network the second is a vector of orders. applet snipet code: System.out.println("beginning writing net"); String choice = "0"; String address = myaddress + "?choice=" + choice; URL url = new URL(address); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); System.out.println("setup writing connection"); // Prepare for both input and ouput con.setDoInput(true); con.setDoOutput(true); // Turn off cahcing con   More>>

I wish to send two object consecutively, the first is a large nerual network the second is a vector of orders.




applet snipet code:
System.out.println("beginning writing net");

String choice = "0";

String address = myaddress + "?choice=" + choice;

URL url = new URL(address);

HttpURLConnection con =
(HttpURLConnection) url.openConnection();

con.setRequestMethod("POST");

System.out.println("setup writing connection");


// Prepare for both input and ouput

con.setDoInput(true);

con.setDoOutput(true);


// Turn off cahcing

con.setUseCaches(false);

con.setDefaultUseCaches (false);


// Set the content type to be application/octet-stream

con.setRequestProperty("Content-Type", "application/octet-stream");


// Write the serialized object as post data

// ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());

ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());

System.out.println("get obj out stream");


//out.writeObject( "I am here" );

out.writeObject( net );

System.out.println("write net");

con.getContent();

out.flush();

out.close();

con.disconnect();


// Update shopping basket

Vector agentOrder = new Vector();

double coff;

try {

coff = Double.parseDouble( this.counterOffer.getText() );

} catch( NumberFormatException nfex ) {

coff = 0;

}

if( this.offerPrice < coff ) {

agentOrder.add( new Item( this.product.model,this.product.name,coff ) );

} else {

agentOrder.add( new Item( this.product.model,this.product.name, Double.parseDouble( this.getPriceRoundedTo2sf( this.offerPrice ) ) ) );

}

for(int i=0; i < this.offerDiscountSelected.size(); i++) {

JCheckBox cb = (JCheckBox) this.offerDiscountSelected.elementAt(i);

if( cb.isSelected()== true ) {

Accessory ac = (Accessory) this.offerVector.elementAt(i);

Item item = new Item( ac.model,ac.name,ac.discountedPrice );

agentOrder.add( item );

}
}


if( agentOrder.isEmpty() == false ) {

System.out.println("beginning writing order");

String choiceA = "2";

String addressA = myaddress2 + "?choice=" + choiceA;

URL urlA = new URL(addressA);

HttpURLConnection conA = (HttpURLConnection) urlA.openConnection();

conA.setRequestMethod("POST");

System.out.println("made connection");


// Prepare for both input and ouput

conA.setDoInput(true);

conA.setDoOutput(true);


// Turn off cahcing

conA.setUseCaches(false);

conA.setDefaultUseCaches (false);


// Set the content type to be application/octet-stream

conA.setRequestProperty("Content-Type", "application/octet-stream");


System.out.println("Write the serialized object as post data");

// Write the serialized object as post data

ObjectOutputStream outA = new ObjectOutputStream(con.getOutputStream());

System.out.println("get obj out stream");

outA.writeObject( agentOrder );

System.out.println("write accessories");

conA.getContent();

outA.flush();

outA.close();

conA.disconnect();

}




Snipet of servlet POST method code: :
log("** Begin reading net from applet **");

ObjectInputStream objin = new ObjectInputStream(request.getInputStream());

log("*$$$$$$$$$$$$$$$$$$* trying to read net from applet *$$$$$$$$$$$$$$$$$4*");

SOMNeuralNetwork k = (SOMNeuralNetwork) objin.readObject();

log("Got the network from the applet: " + String.valueOf(k.weight[1][1]) );

/*
String s = (String) objin.readObject();

log("Got the network from the applet: " + s );

*/
objin.close();

this.setNeuralNet( request,response,k );

log("Finished writing neural net to database");





I wish the applet to close after it finishes sending the data.

Although my neural net object contains preimitive types it should not be a problem since, i can send the netowrk from the servlet to the applet its only reversing this process which is causing my a problem.



Please help soon,
thanks
Kulvinder

   <<Less
About | Sitemap | Contact