• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error in object retrieval through ObjectInputStream  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
public class Applet2 extends JApplet {
public void init() {


URLConnection con = getServletConnection();


// receive result from servlet
InputStream instr = con.getInputStream();

--------------->>ObjectInput inputFromServlet = new ObjectInputStream(instr);
JFreeChart result = (JFreeChart) inputFromServlet.readObject();

ChartPanel chartPanel = new ChartPanel(result);
chartPanel.setPreferredSize(new Dimension(900,600));

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

}catch(IOException e ){System.out.println("Exception in io");} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
}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{}
private void readObjectNoData() {}
// throws ObjectStreamException
private URLConnection getServletConnection()
throws MalformedURLException, IOException {

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


return con;


thanks for help in advance

Posts: 21208
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!