Here's an example of an applet getting info from a servlet. The idea is to
open a URL connection to the servlet, write any arguments to it, open an
inputstream, and read in the results. This code fragment is from an example
in my new book "Professional Java Server Programming" from Wrox Press
(www.wrox.com).
try {
URL url = new URL("http://localhost:8080/servlet/dbServlet");
String qry = URLEncoder.encode("qry") + "="
+ URLEncoder.encode(qryString);
URLConnection uc = url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
uc.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
dos.writeBytes(qry);
dos.flush();
dos.close();
DataInputStream in = new DataInputStream(uc.getInputStream());
String line;
while ((line = in.readLine()) != null) {
taResults.append(line + "\n");
}
in.close();
}
catch(MalformedURLException e) {
taResults.setText(e.toString());
}
catch(IOException e) {
taResults.setText(e.toString());
}
}
I hope this helps you out.
Andrew Patzer
>From: Nathaniel Ye <[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Servlet-applet
>Date: Tue, 31 Aug 1999 09:07:34 -0700
>
>I am trying to implement a tree-view interface on the Web with a database
>backend. The Microsoft way is to use ActiveX control and ADO, but it
>requires their proprietary Web server and platform. I am thinking of using
>a Java applet to do the tree-view and using a servlet to connect to a
>database. At the first phase, there won't be any record update, insert or
>delete.
>If anyone could give me some suggestions and/or procedures on how to
>implement this, especially on how to get the servlet to talk to the applet,
>it would be highly appreciated.
>
>Nathaniel
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html