Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Servlet could not send Objects to an Applet

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have an applet and a servlet. They use http and object-serialization. The communication between them works as long as I send objects only in one direction (either applet->servlet or servlet->applet). But when the servlet should return some objects straightly after receiving an object from the applet, the applet receives nothing.
Thanks

*********************************************************************************************
Applet Code (Method)
*********************************************************************************************
URL url = null;
URLConnection servletConnection = null;
Vector vStg = null;
try {
url = new URL("https://localhost:8080/servlet/vpl");
servletConnection = url.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches (false);
servletConnection.setRequestProperty("Content-type","application/x-java-serialized-object");
ObjectOutputStream outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
Msg outobj = new Msg(Msg.GET_STG);
outputToServlet.writeObject(outobj);
outputToServlet.flush();
outputToServlet.close();
ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
vStg = (Vector) inputFromServlet.readObject();
inputFromServlet.close();
}
catch(Exception g) {
g.printStackTrace();
}
return (vStg);
*********************************************************************************************
Servlet Code
*********************************************************************************************
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
ObjectOutputStream outputToApplet = null;
ObjectInputStream inputFromApplet = null;
try {
response.setContentType("application/x-java-serialized-object");
inputFromApplet = new ObjectInputStream(request.getInputStream());
System.out.println(inputFromApplet);
test = (Msg) inputFromApplet.readObject();
System.out.println(test);
if(test.getAuswahl() == 2) /*Msg.GET_STG*/{
outputToApplet = new ObjectOutputStream(response.getOutputStream());
outputToApplet.writeObject(mytestdat.vPlan);
outputToApplet.flush();
outputToApplet.close();
inputFromApplet.close();
}
}
catch (IOException e) {
e.printStackTrace();
}
catch (java.lang.ClassNotFoundException g) {
g.printStackTrace();
}
}
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try it without closing the outputToServlet stream until after you read the input from servlet. I suspect that closing that stream closes the whole connection. Performing the flush() is enough to complete sending the object.
Bill
 
Richard Huges
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried it, but there was no improvement
 
Richard Huges
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose, that I've tried now every sequence of
new ObjectOutputStream/-InputStream,
write/readObject, flush and close
I don't understand why it doesn't work
hopless Richard
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic