CIS525 - Lecture#23 - November 27, 2000
Chapter 17, cont.
page 948
using Java applets to send getData to CGI programs:
template:
try{
URL cgiURL = new URL(baseURL + "?"
someData);
GetAppletContext();
showDown(cgiURL);
} catch(MalformedURLException mue) {...};
string someData = name1 + "=" + URLEncoder(val1) + "&" +
name2 + "=" + URLEncoder(val2) + "&" +
...
nameN + "=" + URLEncoder(valN) + "&" +
try{
URL cgiURL = new URL(baseURL + "?"
someData);
GetAppletContext();
showDown(cgiURL);
} catch(MalformedURLException mue) {...};
page 951 SearchService.java
page 255, to process html output
1) create a URL object
try {
URL url = new (URL("http://...");
} catch(MalformedURLException mue) {...}
2) create imput stream
3) read each line of html document
string line;
while ((line = in.readLine()) != null)
doSomethingWith(line);
4) close imput stream
page 956 ShowFile.java
Java Applets to send post data to CGI program
1) create URL object
2) create URL connection, object from URL
URLConnection connection = weatherInfo.openConection();
3) specify connection allow output
connection.setDoOutput(true);
4) open output Stream and send post data
PrintStream out = new PrintStream(connection.getOutputStream()):
out.println(name +URLEncoder.encode(value));
5) close output stream
out.close();
see Weather.html page 962
end of Chapter 17
Chapter 18, (the following examples work for elvis, the book may not)
You should look at the following directory for edited versions of
the text program that work on elvis
http://www.engin.umd.umich.edu/~bmaxim/java/
to review CGI interaction process: GET
1) read data sent by GET or POST
2) output http headers, (content-type)
3) send blank line
4) generate document
see page 977 CgiGet.java
``````
passing parameters:
java -Djva = cool
-Dcgi = hot
page 983 CgiCommandLine.java
must add .cgi extension and 'strip out' path info
page 985 IsIndex.java
POST:
CgiPost.java page 099
CgiPost.html page 989, (you need to change extension)