It's not a secret anymore!
The moose likes Servlets and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "" Watch "" New topic

bujji adapa

Joined: Oct 17, 2001
Posts: 11
Iam trying to load applet which calls servlet for a random number.
When i run my applet iam getting an error message as follows:
Error inflating object: Caught EOFException wh
ile reading the stream header Caught EOFException while reading the stream heade
Exception occurred during event dispatching:
at testapplet.drawAxes(
at testapplet.paint(
at sun.awt.RepaintArea.paint(
at java.awt.Component.dispatchEventImpl(
at java.awt.Container.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
at java.awt.EventDispatchThread.pumpEvents(
Can anyone tell me why this is happening?
Please answer to my question....
I also posted a topic two days back for which i did not get any reply.
I expect some positive response this time.
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
Could you possibly post a short snippet of code from your applet showing how you are receiving the information from the servlet and a corresponding piece of code from the servlet side?
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at for other WebSphere information.

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
bujji adapa

Joined: Oct 17, 2001
Posts: 11
Here is my applet code:
public Integer getNumberFromServlet() {
URL url = null;
// Create the URL
String urlStr = "http://localhost:8080/servlet/RandomServlet";
url = new URL( urlStr + "?");
} catch( MalformedURLException e) {
System.out.println(" URL: " + e.toString());
return null;
// Open the stream -- this starts the service() method in the servlet
InputStream inStream = null;
inStream = url.openStream();
} catch( IOException e){
System.out.println("RandomApplet Exception: " + e.toString());
return null;
// Get random number...
Integer randomnum = null;
// Inflage Random number Object
randomnum =
(Integer) inflate( inStream);
return randomnum;
Object inflate( InputStream in){
Object obj = null;

ObjectInputStream objIn = new ObjectInputStream( in);
obj = objIn.readObject();
} catch( IOException e){
System.out.println("Error inflating object: " + e + " " + e.getMessage());
} catch( ClassNotFoundException e){
System.out.println("Error finding class: " + e.getMessage());
return obj;
And my servlet code is:
public void service(javax.servlet.ServletRequest req,javax.servlet.ServletResponse res) throws IOException, ServletException
// Create the output stream for communicating with the Applet
FilterOutputStream objOut = new FilterOutputStream( res.getOutputStream());
byte[] errorDeflatedExam = null;
ServletContext context = getServletContext();
if (context != null) {
context.log("LOG:ReqInfoServlet:service START");
Integer randomnum= rangen.getRandomVal();
// Get a deflated random number Object
byte[] aDeflatedRandomNumber = (byte[]) buildDeflatedRandomNumber(randomnum);
//Write it to the applet
private byte[] buildDeflatedRandomNumber(Integer aint)
//Long randomnum= rangen.getRandomVal();
// Deflate the object to an output stream
ObjectOutputStream objOut = null;
ByteArrayOutputStream bOut = null;
try {
bOut = new ByteArrayOutputStream();
objOut = new ObjectOutputStream(bOut);
} catch ( e) {
return null;
return bOut.toByteArray();

Thanks for the response.
I agree. Here's the link:
It's not a secret anymore!