87 lines
2.6 KiB
HTML
87 lines
2.6 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
|
|
<TITLE>Java CGI HOWTO: Executing a Java CGI Program</TITLE>
|
|
<LINK HREF="Java-CGI-HOWTO-5.html" REL=next>
|
|
<LINK HREF="Java-CGI-HOWTO-3.html" REL=previous>
|
|
<LINK HREF="Java-CGI-HOWTO.html#toc4" REL=contents>
|
|
</HEAD>
|
|
<BODY>
|
|
<A HREF="Java-CGI-HOWTO-5.html">Next</A>
|
|
<A HREF="Java-CGI-HOWTO-3.html">Previous</A>
|
|
<A HREF="Java-CGI-HOWTO.html#toc4">Contents</A>
|
|
<HR>
|
|
<H2><A NAME="s4">4. Executing a Java CGI Program</A></H2>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<H2><A NAME="ss4.1">4.1 Obstacles to Running Java Programs Under the CGI Model</A>
|
|
</H2>
|
|
|
|
<P>There are two main problems in running a Java program from a web server:
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<H3>You can't run Java programs like ordinary executables.</H3>
|
|
|
|
<P>You need to run the Java run-time interpreter and provide the initial
|
|
class (program to run) on the command-line.
|
|
With an HTML form, there is no provision for sending a command-line
|
|
to the web server.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<H3>Java does not have general access to the environment.</H3>
|
|
|
|
<P>Every environment variable that will be needed by the Java program
|
|
must be explicitly passed in.
|
|
There is no method similar to the <B>C</B> <CODE>getenv()</CODE> function.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<H2><A NAME="ss4.2">4.2 Overcoming Problems in Running Java CGI Programs</A>
|
|
</H2>
|
|
|
|
<P>To deal with these obstacles, I wrote a shell CGI program that provides
|
|
the information needed by the Java interpreter.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<H3>The java.cgi script.</H3>
|
|
|
|
<P>This shell script manages the interaction between the HTTP daemon and the
|
|
Java CGI program that you wish to use.
|
|
It extracts the name of the program that you want to run from the
|
|
server-provided data.
|
|
It collects all of the environment data into a temporary file.
|
|
Then, it runs the Java run-time interpreter with the name of the file of
|
|
environment information and the program name added to the command-line.
|
|
<P>The <CODE>java.cgi</CODE> script was configured and installed in
|
|
<A HREF="Java-CGI-HOWTO-2.html#make-programs">Decide On Your Local Path Policies</A>.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<H3>Invoking java.cgi from an HTML form.</H3>
|
|
|
|
<P>My forms that use Java CGI programs specify a form action as follows:
|
|
<PRE>
|
|
<form action="/cgi-bin/java.cgi/CGI_Test" method="POST">
|
|
</PRE>
|
|
|
|
Where <CODE>/cgi-bin/</CODE> is your local CGI binary directory,
|
|
<CODE>java.cgi</CODE> is the Java front-end that allows us to run Java programs
|
|
over the web
|
|
and <CODE>CGI_Test</CODE> is an example of the name of the Java program to run.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<HR>
|
|
<A HREF="Java-CGI-HOWTO-5.html">Next</A>
|
|
<A HREF="Java-CGI-HOWTO-3.html">Previous</A>
|
|
<A HREF="Java-CGI-HOWTO.html#toc4">Contents</A>
|
|
</BODY>
|
|
</HTML>
|