Entry
Can i submit the form fields on an applet to a server side script?
Feb 18th, 2002 21:23
suresh kc, Nagesh Deva, Suresh KC
It doesn't work the way HTML forms do...
as far as I know... there are two ways to work around this problem.
Either you can open the URLConnection
to a servlet or any other server side script
OR
getAppletContext().showDocument(url);
to load that server script in the browser.
the earlier method returns the output to your program.
You will have to construct the url in either cases
For example,
you have a textfield called name
and a when a button called send is clicked you want your server side
script to be called, then you would write something like this:
public class MyApplet extends Applet
implements ActionListener {
URL url;
URLConnection uc;
DataInputStream dis;
...
public void actionPerformed(ActionEvent e) {
String txt = name.getText();
if(txt == null) return;
//case1
try {
url = new URL(s);
uc = new URLConnection (url);
dis = new DataInputStream(uc.getInputStream());
} catch(Exception e) {}
while(true) {
try {
char c = br.readChar();
} catch(Exception e_) {}
}
try {
dis.close();
uc.close();
} catch(Exception e__) {}
//or not both
//case2
try {
url = new URL("/cgi-bin/myscript.pl?name="+txt);
getAppletContext.showDocument(url);
} catch (MalformedURLException mfe) {
showStatus("URL not wellformed");
} catch (UnknownHostException uhe) {
showStatus("Host unreachable");
}
}