dcsimg
Need help on sending serialized object from servlet to applet! keep getting "Caught EOFException while reading the stream header" ...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Roland_Honegger
Posted On:   Wednesday, March 27, 2002 04:36 AM

Hello i'm relatively new to serialization and servlet-applet communication, but i thought that i've learned a lot reading through the discussions on this webpage. anyway, i just don't get things working like they should ... the problem is, when i want to get the inputstream in the applet with ObjectInputStream in = new ObjectInputStream(conn.getInputStream()); , then an IO Exception: java.io.StreamCorruptedException: Caught EOFException while reading the stream header occurs. here the complete code: part of the applet which should receive the object from the servlet: public String[] readData() { try{ System.out.println("Try to open Connection .   More>>

Hello


i'm relatively new to serialization and servlet-applet communication, but i thought that i've learned a lot reading through the discussions on this webpage. anyway, i just don't get things working like they should ...


the problem is, when i want to get the inputstream in the applet with ObjectInputStream in = new ObjectInputStream(conn.getInputStream()); , then an IO Exception: java.io.StreamCorruptedException: Caught EOFException while reading the stream header occurs.


here the complete code:


part of the applet which should receive the object from the servlet:


			
public String[] readData() {
try{
System.out.println("Try to open Connection ...");
URLConnection conn = getDataURL().openConnection();
System.out.println("Connection to " + conn.toString() +" opened!");
conn.setUseCaches(false);
conn.setDefaultUseCaches(false);

conn.setRequestProperty("Content-type", "application/x-java-serialized-object");
System.out.println("Getting Input Stream ...");
ObjectInputStream in = new ObjectInputStream(conn.getInputStream()); // ---> here occurs the IO Exception!
System.out.println("Reading data ...");
String[] inString = (String[])in.readObject();
in.close();
System.out.println("Connection closed!");
return inString;
} catch(IOException IOE) {
System.out.println("IO Exception: " + IOE);
} catch(Exception E) {
E.printStackTrace();
}
return null;
}

private URL getDataURL() {
try {
URL currentPage = getCodeBase();
System.out.println("CodeBase: "+currentPage.toString());
String protocol = currentPage.getProtocol();
String host = currentPage.getHost();
int port = currentPage.getPort();
String urlSuffix = "servlet/countservlet";
URL dataURL = new URL(currentPage.toString() + urlSuffix);
System.out.println("complete URL: " + dataURL.toString());
return dataURL;
} catch (MalformedURLException MUE) {
System.out.println("URL Exception:" + MUE);
}
return null;
}


and here the corresponding servlet:


			
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

String contentType = "application/x-java-serialized-object";
res.setContentType(contentType);

try {
System.out.println("Open OutputStream to Applet!");
ObjectOutputStream out = new ObjectOutputStream(res.getOutputStream());
String[] resToApplet = DataFile.readFile(requestID);
out.writeObject(resToApplet);
out.flush();
// out.close();
System.out.println("DataFile sent to Applet!");
} catch(IOException IOE) {
System.out.println("IOException: " + IOE);
}
}



any help would be greatly appreciated


thanx

Roland Honegger

   <<Less

Re: Need help on sending serialized object from servlet to applet! keep getting "Caught EOFException while reading the stream header" ...

Posted By:   subodh_kumar  
Posted On:   Monday, June 10, 2002 12:16 AM

public String[][] getDataFromServlet(){
try {

URL url=new URL("http://29.0.0.10:8080/examples/servlet/ServletDB");
java.net.URLConnection con = url.openConnection();
System.out.println("Connection status"+""+con);
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
System.out.println("inside the lsdkflsdkfl;ksdlfk");
ObjectInputStream is=new ObjectInputStream(con.getInputStream());
System.out.println("waiting for response ");
arrayServlet=(String[][])is.readObject();
for(int j=0;j<18;j++) {
System.out.println(arrayServlet[j][0]+" "+arrayServlet[j][1]+" "+arrayServlet[j][2]+ " "+arrayServlet[j][3]);
System.out.println();
}
is.close();
//return arrayServlet;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
return arrayServlet;
}
About | Sitemap | Contact