Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Applet Servlet Communication

Posted on 2009-05-04
6
542 Views
Last Modified: 2013-11-23
I am sending HashMap from Applet to Servlet but when the servlet tries to read the input stream of the request object using the following code :-
              InputStream in = request.getInputStream();
              ObjectInputStream inputFromApplet = new ObjectInputStream(in);
It throws an exception java.io.EOFException.
Any idea what is going wrong here .
0
Comment
Question by:jdpositive
  • 3
  • 2
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 24300286
how is the servlet sending it?

0
 
LVL 92

Expert Comment

by:objects
ID: 24300309
(meant applet)
0
 

Author Comment

by:jdpositive
ID: 24300350
Pasting the code snippet :-
a)Applet
      urlServlet = new URL("http://tools-dev.cisco.com/support/downloads/dlcws/DownloadManagerServlet");
   conn = urlServlet.openConnection();
   conn.setDoInput(true);
   conn.setDoOutput(true);
   conn.setUseCaches(false);
   conn.setRequestProperty("Content-Type","application/x-java-serialized-object");
   
   //Send object to the servlet
   HashMap inputParametersMap = new HashMap();
   inputParametersMap.put("userId", userId);
   inputParametersMap.put("cartId", cartId);
   
   OutputStream outstream = conn.getOutputStream();
   ObjectOutputStream oos = new ObjectOutputStream(outstream);
   oos.writeObject(inputParametersMap);
   oos.flush();
   oos.close();
b)Servlet

   String userId = null;
   String cartId = null;
   String operation = null;
   ArrayList cartList = new ArrayList();
   OutputStream outstr = response.getOutputStream();
   ObjectOutputStream oos = new ObjectOutputStream(outstr);
 
   try
   {
    response.setContentType("application/x-java-serialized-object");
    //read a String-object from applet
    // instead of a String-object, you can transmit any object, which
    // is known to the servlet and to the applet
    InputStream in = request.getInputStream();
    ObjectInputStream inputFromApplet = new ObjectInputStream(in); //Throws Exception here
    HashMap inputParametersMap = (HashMap) inputFromApplet.readObject();
0
 
LVL 92

Expert Comment

by:objects
ID: 24300963
can't see a problem there, as a test try removing:

   OutputStream outstr = response.getOutputStream();
   ObjectOutputStream oos = new ObjectOutputStream(outstr);


0
 

Accepted Solution

by:
jdpositive earned 0 total points
ID: 24301111
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question