Solved

Applet Servlet Communication

Posted on 2009-05-04
6
541 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Notepad++ search not working 6 1,277
Azure iOS apps: what devices will these run on 4 113
Eclipse. How to move up/down source folders 4 86
Unable to start eclipse ? 17 141
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…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

813 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

19 Experts available now in Live!

Get 1:1 Help Now