• Post Reply Bookmark Topic Watch Topic
  • New Topic

sending and reading Hashtable from applet to servlet  RSS feed

 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys!
I have a servlet running on tomcat server, I have stablished HTTP connection from applet (or just a simple java bean class). I am
trying to read and send the hashtable to the servlet but i m getting
EOF exception. Can any one help me out to solve this problem??
my client class looks like this:

public class EditorStub {
private static String sessionID="anshdhLLlksjsj";
private static String URL ="http://repgen:8080/QuickView/EditorGateway";
public static Hashtable sendRequest(Hashtable requestParams)
throws Exception {
requestParams.put("1","sssssssssssssssssssss");
requestParams.put("SESSION_ID",sessionID );
URL url = new URL(URL);
URLConnection connection = url.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
ObjectOutputStream requestStream = new ObjectOutputStream(connection.getOutputStream());
ObjectInputStream responseStream = new ObjectInputStream(connection.getInputStream());
requestStream.writeObject(requestParams);
responseStream.readObject();
return null;//htResponse;

}

public static void main(String[] args){
try{
Hashtable response = new Hashtable();
response.put("1","stub dummy values");
EditorStub.sendRequest(response);
}catch(Exception e){
e.printStackTrace();
}
}
}
and the servlet codes:
public void service(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

try{
fos = new FileOutputStream(new File("commLog.txt"));
}catch(Exception e){
e.printStackTrace();}
write("EditorGateway : service method called...");
ObjectInputStream requestStream = new ObjectInputStream(request.getInputStream());
ObjectOutputStream responsStream = new ObjectOutputStream(response.getOutputStream());

try{
Hashtable requestParams = (Hashtable) requestStream.readObject();
Hashtable responseParams;
}catch(Exception e){
e.printStackTrace();
}finally{
try{
responsStream.flush();
responsStream.close();
requestStream.close();
fos.flush();
fos.close();
}catch(Exception ex){}
}
} // service method ends
can any one please help me where i m making mistake?
or is there any way to read hashtable or hashmap??
these classes implements seriazable, so it should
not b a prob to read.
thanks in advance
Tausif
 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
guys guys guys!!!
i forgot to mention one more exception which i m getting
i.e.
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2423)
got any hint??
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I see a couple of problems. The client code sends some data, but does not flush or close the stream, so the servlet won't get all the data, leading to exactly the kind of errors you describe; and again, the client code calls readObject(), but the servlet never sends one -- it only flushes and closes the stream, without ever putting any data onto it.
 
Tausif Khanooni
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
It really helped me..
cya!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!