Discussion Locked

applet communication

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
how can an applet communicate with a database & how can we use applets to communicate with servlet

9 replies

by chakravartyanirban77

Making an Applet to communicate with a database requires either the applet to open a socket connection to a Server Application listening on a port or communication with a servlet which interacts with the database. An applet can communicate with a servlet with the help of AppletContext. The Applet class has a method getAppletContext() which returns the current AppletContext. Call the method showDocument(URL,String) of the AppletContext object and pass the url and a String to specify whether to show the document in the same browser window or not.
e.g
AppletContext ap=getAppletContext();
ap.showDocument(new URL("http://hostname/servlets/MyServlet?name=Myname&address=MyAddress","_self");
Displays in the same window
AppletContext ap=getAppletContext();
ap.showDocument(new URL("http://hostname/servlets/MyServlet?name=Myname&address=MyAddress","_blank");
Displays in a new Window

by chakravartyanirban77

Making an Applet to communicate with a database requires either the applet to open a socket connection to a Server Application listening on a port or communication with a servlet which interacts with the database. An applet can communicate with a servlet with the help of AppletContext. The Applet class has a method getAppletContext() which returns the current AppletContext. Call the method showDocument(URL,String) of the AppletContext object and pass the url and a String to specify whether to show the document in the same browser window or not.
e.g
AppletContext ap=getAppletContext();
ap.showDocument(new URL("http://hostname/servlets/MyServlet?name=Myname&address=MyAddress","_self");
Displays in the same window
AppletContext ap=getAppletContext();
ap.showDocument(new URL("http://hostname/servlets/MyServlet?name=Myname&address=MyAddress","_blank");
Displays in a new Window

by chakravartyanirban77

Making an Applet to communicate with a database requires either the applet to open a socket connection to a Server Application listening on a port or communication with a servlet which interacts with the database. An applet can communicate with a servlet with the help of AppletContext. The Applet class has a method getAppletContext() which returns the current AppletContext. Call the method showDocument(URL,String) of the AppletContext object and pass the url and a String to specify whether to show the document in the same browser window or not.
e.g
AppletContext ap=getAppletContext();
ap.showDocument(new URL("http://hostname/servlets/MyServlet?name=Myname&address=MyAddress"),"_self");
Displays in the same window
AppletContext ap=getAppletContext();
ap.showDocument(new URL("http://hostname/servlets/MyServlet?name=Myname&address=MyAddress"),"_blank");
Displays in a new Window

The previous answer had an Error.

by jamshedd

one Very imp point to remember during applet servlet communication is that
When u open an input stream in the applet
the doGet methos is called in the servlet
And when u open an output stream the doPost methos is called
you must also establish a 2 way connection
ie u must also open the corresponding streams in the servlet
else u will get fienotfound exceptions

This discussion is closed to new replies.