• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Error in object retrieval through ObjectInputStream  RSS feed

 
Greenhorn
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.
*/
@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

 
Sheriff
Posts: 21459
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!