[0001] [0002] [0003] [0004] [0005] [0006] [0007] [0008] [0009] [0010] [0011] [0012] [0013] [0014] [0015] [0016] [0017] [0018] [0019] [0020] [0021] [0022] [0023] [0024] [0025] [0026] [0027] [0028] [0029] [0030] [0031] [0032] [0033] [0034] [0035] [0036] [0037] [0038] [0039] [0040] [0041] [0042] [0043] [0044] [0045] [0046] [0047] [0048] [0049] [0050] [0051] [0052] [0053] [0054] [0055] [0056] [0057] [0058] [0059] [0060] [0061] [0062] [0063] [0064]
// postCGIplus.java // Compile using: $ javac "postCGIplus.java" // // 03-JUN-2000 MGD less sloppy CGI, add header! // 03-SEP-1998 MGD changes in line with JDK 1.1.6 final release // 09-DEC-1997 MGD initial // // Example of POSTed, "x-www-form-urlencoded" processing. // Can be invoked using ... http://host/cgiplus-bin/postcgiplus.class import java.io.*; public class postcgiplus { private static CGIplus cgienv = new CGIplus(); private static String nameValue = null; public static void main (String args[]) { /* CGIplus "infinite loop" */ for (;;) { cgienv.begin(); // CGI-compliant plain-text header (and pre-expired) System.out.print("Content-Type: text/plain\n" + "Expires: Thu, 01-Jan-1970 00:00:01 GMT\n\n"); System.out.println("There are " + cgienv.getCgiVarCount() + " CGI variables ..."); while ((nameValue = cgienv.nextCgiVar()) != null) System.out.print(nameValue); System.out.println(""); if (cgienv.isPOSTedForm()) { System.out.print("Content-Type: " + cgienv.getCgiVar("CONTENT_TYPE")); System.out.println(""); System.out.print("Dump of form fields ..."); while ((nameValue = cgienv.nextFormField()) != null) System.out.print(nameValue); System.out.println(""); System.out.print("Field \"hidden1\": " + cgienv.getFormField("hidden1")); System.out.print("Field \"hidden2\": " + cgienv.getFormField("hidden2")); System.out.print("Field \"hidden3\" (which doesn't exist): " + cgienv.getFormField("hidden3")); System.out.print("Field \"userinput\": " + cgienv.getFormField("userinput")); } else { System.out.print("Request was not POSTed!"); } cgienv.end(); } } }