Discussion Locked

applet communication

0 helpful
6 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

6 replies

by sampathr

to communicate applets to servlet , do the following.

URL newURL = new URL("http",hostName,port,newPath);Frame the URL
AppletContext context = getAppletContext();
context.showDocument(newURL,"bottom");

Here u could see that u can use the showDocument method of Appletcontext, which can be retrived from getAppletcontext().

I hope this will answer ur 2nd part of the question.

For the 1st part of question :
Use TrustedCode for the applet, then it will allow u to connect with database.

Sampath Ramanujan.

by ravalv

Hi,

U can use following code to communicate with the servlet from applet where p1 and p2 are the parameters and v1 and v2 are the values of the parameter which are passed to the servlet:

url = new URL("http://server:8080/servlet/servletname");
StringBuffer arg = new StringBuffer("?");
arg.append(URLEncoder.encode("P1") + "=" + URLEncoder.encode("V1"));
arg.append("&");
arg.append(URLEncoder.encode("P2") + "=" + URLEncoder.encode(V2));

url = new URL(url.toExternalForm() + arg.toString());

con = url.openConnection();
con.setUseCaches(false);

in = con.getInputStream();

DataInputStream data = new DataInputStream(new BufferedInputStream(in));

String incoming = data.readLine();

Alos at the servlet in response set the content type text/plain.

Vishal Raval

by ravalv

If you want the detailed code to communicte with server from the applet or want to use database of the server from the applet contact me at the ravalv@rediffmail.com

This discussion is closed to new replies.