Demo
Note: Demo not fully functional.
Description
This applet allows a visitor of page to add an entry to the guestbook. This entry is send to the through the applet, which uses a CGI help it write the entry to the guestbook database as a HTML document. This applet requires a CGI which only performs the process of taking a string and writing it to a file. For my particular applet, I have written the CGI in C which is similar to the one below:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main(int argc, char *argv[]) {
FILE *fp; char *method;
char line[BUFSIZ];
printf("Content-type: text/html\n\n");
if ((fp = fopen(argv[1], argv[2])) == NULL) {
printf("Can't open the file %s with mode [%s]\n", argv[1], argv[2]);
exit(EXIT_FAILURE);
}
method = getenv("REQUEST_METHOD");
if (method == NULL) {
printf("Use POST method with HTML form.\n");
exit(EXIT_FAILURE);
}
else if (strcmp(method, "POST") == 0 || strcmp(method, "GET") == 0) {
while(!feof(stdin)) {
fgets(line, sizeof(line), stdin);
fprintf(fp, "%s", line);
fflush(fp);
}
}
fclose(fp);
}
Usage/Parameters
| cgi | The CGI which writes the data the HTML document. |
| guestPath | The directory and name of where the guestbook file is location in the server. |
| guestURL | The URL of the guestbook. |
Example
Here is an example of the HTML source code for embedding this applet:
<applet archive="GuestBook.jar" code="GuestBook.class" codebase="classes" width="400" height="250">
<param name="cgi" value="cgi-bin/writefile.cgi">
<param name="guestPath" value="guestbookdemo.html">
<param name="guestURL" value="guestbookdemo.html">
</applet>
Version Updates
None
Download
Download this applet now. (source code included)
