aspose file tools*
The moose likes Servlets and the fly likes How To Connect a Servlet with an Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How To Connect a Servlet with an Applet" Watch "How To Connect a Servlet with an Applet" New topic
Author

How To Connect a Servlet with an Applet

vijay malhotra
Greenhorn

Joined: Nov 26, 2000
Posts: 26
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

Joined: Jan 23, 2001
Posts: 95
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


Thankx
Ajit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How To Connect a Servlet with an Applet