Solved

Applet Servlet Communication

Posted on 2009-05-04
6
549 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
[X]
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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

729 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