At 03:55 PM 2/26/99 -0600, you wrote:
>The following message was posted to this list yesterday, but no one
>answer me. Could someone reply to me? I also feel crazy.
I meant to reply but forgot.
>I am new to this list. I have a question about how to make applet to
>communicate with servlet which was started by servletrunner. I know
>for form, it uses :
>
> <form action=http://machine:8080/servlet/survey method=POST>
>
>to access the server when the form is submitted. But how about if the
>applet is embeded in html file? Is there a way?
Here is a code snippet, hopefully enough of the non-essential
stuff removed so that it gets the idea across. You open a URL
connection and communicate with it: post to it and then read the
response. This is described in Jason Hunter's Servlets book and
the imported classes are available at com.oreilly, if I recall
correctly. The servlet I call is returning "plain/text" (I'm not
sure if that was required but I didn't want html).
Suzanne
---------------
import com.oreilly.servlet.HttpMessage;
.
.
.
String line_in;
OutputStream os;
InputStream in;
URL url;
URLConnection connection;
try
{
url = new URL("http://machine:8080/servlet/survey");
}
catch (MalformedURLException murle)
{ return(false);
}
// open a connection to your servlet
HttpMessage msg = new HttpMessage(url);
// post the parameters. My servlet responds with plain/text.
Properties props = new Properties();
props.put("parameter", parameter_value);
// get the results from the connection (what this
// program considers input)
try
{
in = msg.sendGetMessage(props);
}
catch (IOException ioe)
{ return(false);
}
BufferedReader br = new BufferedReader(new
InputStreamReader(in));
try
{
line_in = br.readLine();
if (line_in != null && line_in.equals("0"))
{
// here, I'm just reusing a string I no longer
need
parameter_value = br.readLine();
line_in = br.readLine();
// someone's going to put comments in
inadvertently..
while (line_in != null &&
line_in.startsWith("#"))
line_in = br.readLine();
}
// sort out the input
if (line_in.toUpperCase().startsWith("DESC"))
{
title = line_in.substring(5);
line_in = br.readLine();
}
else
title = new String("");
while (line_in != null)
{
boolean more;
more = true;
do
{
line_in = br.readLine();
if (<test condition>)
more = false;
} while (line_in != null && more);
// do stuff here
}
br.close();
}
catch (IOException e)
{ return(false);
}
return(true);
}
___________________________________________________________________________
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