import java.io.*;
// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.
public class ShowParse extends CgiShow {
public static void main(String[] args) {
String method = System.getProperty("REQUEST_METHOD");
String[] data = new String[1];
if ("GET".equalsIgnoreCase(method))
data[0] = System.getProperty("QUERY_STRING");
else {
try {
DataInputStream in =
new DataInputStream(System.in);
data[0] = in.readLine();
} catch(IOException ioe) {
System.out.println("IOException: " + ioe);
System.exit(-1);
}
}
ShowParse app = new ShowParse("ShowParse", data,
method);
app.printFile();
}
public ShowParse(String name, String[] queryData,
String requestMethod) {
super(name, queryData, requestMethod);
}
protected void printBody(String[] queryData) {
QueryStringParser parser =
new QueryStringParser(queryData[0]);
LookupTable table = parser.parse();
String[] names = table.getNames();
String[] values = table.getValues();
System.out.println("Request method: " +
type + ".
");
if (names.length > 0)
System.out.println("Data supplied:\n" +
"
| Name | Value(s)");
else
System.out.println("No data supplied."); String name, value; String[] fullValue; for(int i=0; i" + name);
if (table.numValues(name) > 1) {
fullValue = table.getFullValue(name);
System.out.println
(" | Multiple values supplied:\n" +
" |
No Value Supplied");
else
System.out.println
(" | " + value);
}
}
System.out.println(" | |
|---|