aspose file tools*
The moose likes I/O and Streams and the fly likes Error in object retrieval through ObjectInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Error in object retrieval through ObjectInputStream" Watch "Error in object retrieval through ObjectInputStream" New topic
Author

Error in object retrieval through ObjectInputStream

sravan kumar kachavarapu
Greenhorn

Joined: Oct 10, 2009
Posts: 1
hi everyone, i am struggling with this problem

i am getting error while retrieving object through ObjectInputstream.
i have a jsp which contains an applet, in this jsp i set one araylist as object by session.setAttribute
and call the applet, this applet intern calls a servlet which takes the session object and then generates an graph object and puts in outputstream.
the applet captures the outputstream and dispalys the graph.

but i am having error while retrieving the graph object, is there any problem because of the session object

here is the code for applet which is throwing the error at marked by ---------->>


import java.awt.Container;
import java.awt.Dimension;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

import javax.swing.JApplet;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

/**
* Simple demonstration for an Applet <-> Servlet communication.
*/
@SuppressWarnings("serial")
public class Applet2 extends JApplet {
public void init() {

try{

URLConnection con = getServletConnection();

System.out.println("5");


// receive result from servlet
InputStream instr = con.getInputStream();
System.out.println("8");

--------------->>ObjectInput inputFromServlet = new ObjectInputStream(instr);
System.out.println("69");
JFreeChart result = (JFreeChart) inputFromServlet.readObject();
//inputFromServlet.close();
//instr.close();

System.out.println("1");
ChartPanel chartPanel = new ChartPanel(result);
chartPanel.setPreferredSize(new Dimension(900,600));

chartPanel.setPopupMenu(null);
//add the chartPanel to the container (getContentPane is inherited from JApplet which AppletGraph extends).
Container content = getContentPane();
content.add(chartPanel);

}catch(IOException e ){System.out.println("Exception in io");} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(SecurityException e1){System.out.println("Exception in security");}
catch(NullPointerException e2){System.out.println("Exception as null");}}
/**
* Get a connection to the servlet.
*/
private void writeObject(java.io.ObjectOutputStream stream)
throws IOException{}
private void readObject(java.io.ObjectInputStream stream)
throws IOException, ClassNotFoundException{}
@SuppressWarnings("unused")
private void readObjectNoData() {}
// throws ObjectStreamException
private URLConnection getServletConnection()
throws MalformedURLException, IOException {


URL urlServlet = new URL("http://localhost:8080/trail2/Servlet3");
URLConnection con = urlServlet.openConnection();
System.out.println("9");

con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty(
"Content-Type",
"application/x-java-serialized-object");


return con;
}

}



thanks for help in advance

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19552
    
  16

Please Use Code Tags.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error in object retrieval through ObjectInputStream
 
Similar Threads
PROBLEMS WITH APPLET -> SERVLET communication
Issues regarding Applet-Servlet communication
Signed applet talking to server other than its own
Swing - servlet communication
HELP! Applet's trouble with Servlet's response