• Here's a link that sends a query string to the script titled j_invoker.php
    <a href="j_invoker.php?blahblahblah&blah234567">
  • Script source code
  • Java source code

    This means that we can use java as an adjunct to our scripting. We might want to do this because the String class in java allows us to manipulate QUERY_STRING without worrying as much about special characters like ! & < > *, etc.


    Things to notice:
    The parser.java program writes the Content-type and header information sent back to the httpd. The usual cgi line:
    	echo "Content-type: text/html"
    	echo ""
    
    becomes:
    	System.out.println("Content-type: text/html");
    	System.out.println("\n");
    
    The backslash-n tells is how an endline character is written in java (and C, and in fact, in csh also).
    Here's a link that invokes a slightly more sophisticated version of parser.java called parser2.java. The new invoker is called j2_invoker.php?arg1&arg2&arg3

    So, if we were to use a form, we would be able to separate our different arguments using that same script and java program:
    Name:
    Age:
    Serial #:

    This form sends its input, arg1, arg2, and arg3 to the j2_invoker.php script. Using the GET method, this adds an ampersand separated string to the URL:
    	http://yourhost.edu/j2_invokder.cgi?arg1=blah&arg2=blah&arg3=blah
    
    So, the cgi script gives this QUERY_STRING to our java program, parser2.java and it strips away the ampersands. I also used a utility called StringTokenizer which helps separate the space-separated arguments into their own strings.
    Assignment:

    Create a form, which will use a similar process to these examples. Extend the functionality of the script by parsing out unwanted +'s, and replacing the %hex numbers with good values. For a table of equivalences, look here. And for hints look here Here's my example solution