** Start of listing of h3-java.cgi ** ** End of listing of h3-java.cgi ** Here is the directory entry for that file: ^ Note user execute permission needed for all CGI scripts. ** Start of listing of H3.java ** import java.util.Date; import java.text.SimpleDateFormat; import java.util.Properties; import java.util.Enumeration; import java.util.StringTokenizer; import java.net.URLDecoder; import java.util.HashMap; public class H3 { public static void main(String args[]) { System.out.println("Content-type: text/plain;charset=us-ascii"); System.out.println(""); Properties pr = System.getProperties(); Enumeration en = pr.propertyNames(); while (en.hasMoreElements()) { Object oKey = en.nextElement(); String sKey = (String)oKey; String sVal = pr.getProperty(sKey); //System.out.println("Key[" + sKey + "] -> [" + sVal + "]"); } String rm = pr.getProperty("cgi.request_method"); System.out.println("** Request method is " + rm); String efc; // Encoded Form Contents, comes from different places below if ("GET".equals(rm)) { System.out.println("Good! I can do GET."); String qs = pr.getProperty("cgi.query_string"); System.out.println("** Query string is " + qs); efc = qs; } else { String sCL = pr.getProperty("cgi.content_length"); System.out.println("Content length (string) = " + sCL); int nCL = Integer.parseInt(sCL); System.out.println("Content length (int) = " + nCL); byte[] buf = new byte[nCL]; try { int nRead = System.in.read(buf, 0, nCL); System.out.println("Number of bytes actually read = " + nRead); } catch (Exception ex) { System.out.println("Got an exception: " + ex); return; } efc = new String(buf); System.out.println("Encoded form contents (from std.input) is " + efc); } System.out.println(""); HashMap hm = new HashMap(); StringTokenizer st = new StringTokenizer(efc, "&"); while (st.hasMoreTokens()) { String pair = st.nextToken(); System.out.println("Pair is " + pair); StringTokenizer st2 = new StringTokenizer(pair, "="); try { String key = URLDecoder.decode(st2.nextToken()); String val = URLDecoder.decode(st2.nextToken()); System.out.println("Key=[" + key + "] val=[" + val + "]"); hm.put(key,val); } catch (Exception ex) { System.out.println("Got exception: " + ex); return; } if (st2.hasMoreTokens()) { System.out.println("(More than 2)"); } } System.out.println(""); String fn = (String)(hm.get("firstname")); String ln = (String)(hm.get("lastname")); String fav = (String)(hm.get("favorite number")); System.out.println("Howdy, stranger. May I call you '" + fn + " " + ln + "',"); System.out.println("or would you prefer I call you '" + ln + ", " + fn + "'?"); System.out.println("By the way, is your favorite number really " + fav + "?"); } } ** End of listing of H3.java ** Here is the directory entry for that source file and its compilation: -rw------- 1 rem user 2676 Feb 28 2007 H3.java -rw------- 1 rem user 3151 Feb 28 2007 H3.class ^ Note user execute permission *not* needed for separate program files.