Skip to main content

EOF error

No replies
ratebuster
Offline
Joined: 2007-10-14
Points: 0

hello guys, i am writing applet-servlet communication application, i am getting this error, which i am unable to resolve after digging into google also, hope someone here could help me get rid of the error. thanks in advance

code at applet

....
URL url = new URL(getCodeBase(), "NewServlet");
URLConnection con = url.openConnection();

con.setUseCaches(false);
con.setDoOutput(true);
con.setDoInput(false);

ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(stream);
oos.writeObject(obj);
oos.flush();
oos.close();

byte[] buf = stream.toByteArray();
// con.setRequestProperty ("Content-Type", "application/x-java-serialized-object");
con.setRequestProperty("CONTENT-LENGTH",Integer.toString(buf.length));

DataOutputStream dataout = new DataOutputStream(con.getOutputStream());
dataout.write(buf);
dataout.flush();
dataout.close();
....

code at servlet

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doPost(request, response);
....
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
InputStream in = request.getInputStream();
try
{
ObjectInputStream ois = new ObjectInputStream(in);
}
catch(EOFException e1)
{
System.out.println(" EXCEPTION ");
e1.printStackTrace();
}
....
}

java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2279)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2748)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
at java.io.ObjectInputStream.(ObjectInputStream.java:280)
at NewServlet.doPost(NewServlet.java:112)
at NewServlet.doGet(NewServlet.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:619)

also another thing :
when i do System.out.println(" Content Length = " + request.getContentLength()); it shows -1

and at applet side when i write
JOptionPane.showMessageDialog(this,"Priting buf length \n" + buf.length,"Testing!!" , JOptionPane.WARNING_MESSAGE); it shows 501
while
JOptionPane.showMessageDialog(this,"Priting con length \n" + con.getContentLength(),"testing!!" , JOptionPane.WARNING_MESSAGE); shows 234