Solved

Applet Servlet Communication

Posted on 2009-05-04
6
535 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
Comment Utility
how is the servlet sending it?

0
 
LVL 92

Expert Comment

by:objects
Comment Utility
(meant applet)
0
 

Author Comment

by:jdpositive
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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 connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now