This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How To Connect a Servlet with an Applet
 
Similar Threads
Applet upload/download image to/from database via Servlet
database connectivity
Front-End To Servlets
Hidden Applet?
Iam not able to connect to database using applets