File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To Connect a Servlet with an Applet

 
vijay malhotra
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell me how to connect an applet to a servlet ?
Give a small piece of code and some other documentation
available on the net .
 
Ajit Kanada
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vijay
u need to write following lines in ur Servlet...
ObjectOutputStream ToApplet=new ObjectOutputStream(response.getOutputStream());
ToApplet.writeObject("name of the obj to be written to applet");
ToApplet.flush();
ToApplet.close();
u need to write following lines in ur Applet...
String servletLocation ="http://localhost:8080/servlet/nameofurservlet;
URL empDBservlet = new URL( servletLocation);
URLConnection servletConnection = empDBservlet.openConnection();
servletConnection.setUseCaches (false);
servletConnection.setDefaultUseCaches(false);

ObjectInputStream FromServlet = new ObjectInputStream(servletConnection.getInputStream());
//read the values from the input stream....
gnames = (String) FromServlet.readObject();
------------------------
in gnames u will get the values written by servlet

i think this will solve ur problem
best luck
Ajit

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic