| This example shows how to use MINERVA as a servlet with Tomcat/Jakarta/Apache.
The servlet minserve takes some user information
from an HTML FORM element, then echos the user information
in HTML, XML or plain text.
The example shows how the MINERVA servlet predicates
are called by FORM methods GET or POST, how to
get the input parameters from the servlet request,
build a Prolog term, convert it to the desired format
and write it back to the servlet response to
the HTTP client. Every step is logged to the server log.
The example has been prepared using the Jakarta Tomcat 3.2 and 4.0
servlet web servers by the Apache Software foundation,
http://jakarta.apache.org/tomcat/index.html
and Sun Java JDK1.4.
The example consists of the following files:
minserve.html
- HTML file that contains the HTML FORM element.
minserve.min
- MINERVA servlet program
web.xml
- Tomcat control file that maps the servlet to its URL
and tells Tomcat which MINERVA file it should load
A listing of the predicates provided by MINERVA is
servlet.mpk
- servlet built-in predicates
These predicates correspond to their counterparts of the Java Servlet
interface.
Running the Example
Follow these steps to install and run the example.
The commands are given in UNIX/Linux conventions,
adapt for other operating systems as needed.
- Install MINERVA and TOMCAT
In the following we assume that
MINERVA is installed at $MINERVA_HOME and
Tomcat is installed at $CATALINA_HOME.
- Make a servlet directory
mkdir $CATALINA_HOME/webapps/minserve
mkdir $CATALINA_HOME/webapps/minserve/WEB-INF
mkdir $CATALINA_HOME/webapps/minserve/WEB-INF/minerva
mkdir $CATALINA_HOME/webapps/minserve/WEB-INF/classes
- Copy HTML file to servlet directory
cp minserve.html $CATALINA_HOME/webapps/minserve
- Copy MINERVA system files to the servlet directory
cp -r $MINERVA_HOME/com $CATALINA_HOME/webapps/minserve/WEB-INF/classes
cp -r $MINERVA_HOME/servlet/WEB-INF/classes/com $CATALINA_HOME/webapps/minserve/WEB-INF/classes
cp $MINERVA_HOME/minerva.mca $CATALINA_HOME/webapps/minserve/WEB-INF/minerva
cp $MINERVA_HOME/servlet/WEB-INF/minerva/servlet.mpk $CATALINA_HOME/webapps/minserve/WEB-INF/minerva
- Copy servlet program to the servlet directory
cp minserve.min $CATALINA_HOME/webapps/minserve/WEB-INF/minerva
- Compile the servlet program
minervac minserve.min
- Restart the Tomcat server
$CATALINA_HOME/bin/shutdown.sh
$CATALINA_HOME/bin/startup.sh
- Invoke the servlet
In a default installation of Tomcat, the URL will be
http://localhost:8080/minserve/minserve.html
|