Hello Java Servlet
This servlet was developed using Java 1.3 and Tomcat 4.0. There is one source
code file named Hello.java. It supports both a GET and POST operation. The GET
puts up a simple form for you to enter the full pathname of HELLO.XPL. The POST
calls the Amzi! Logic Server and displays the result.
Building the Sample
- Set JAVA_HOME=c:\jdkN.N
- Set the CLASSPATH to include .;\amzi\lsapis\java20 and servlet.jar. For
Tomcat, servlet.jar is found in jakarta-tomcat-X.X\common\lib.
- Compile Hello.java with javac.
- Compile hello.pro with acmp (or the Amzi! IDE) and link it into hello.xpl
with alnk (or the Amzi! IDE).
JRUN
In order to run this servlet under JRUN, you need to modify Hello.java in the
method doGet() to read
out.println("<form method=post action=\"/servlet/Hello\">");
instead of:
out.println("<form method=post action=\"/amzi/Hello\">");
This is because the default URL for servlets under JRUN is /servlet.
Running the Sample
Tomcat
Under Unix, Tomcat generally installs in a directory named jakarta-tomcat-X.X.
Under Windows, the directory is called 'Apache Tomcat X.X. The examples
below use the Windows naming. If you are running under Unix, make the appropriate
substitutions.
In order to run this servlet under Tomcat (where X.X is replaced by
the version of Tomcat you are running, and N.N by the version of Java
you are running):
- Create a sudirectory in ...Apache Tomcat X.X\webapps named 'amzi'.
- Copy the amzi\samples\internet\servlets\hello\WEB-INF subdirectory tree
to ...Apache Tomcat X.X\webapps\amzi.
- Copy Hello.class to ...Apache Tomcat X.X\webapps\amzi\WEB-INF\classes
- Copy Hello.xpl to ...Apache Tomcat X.X\webapps\amzi
- Copy amzi.dll, amzijni.dll (from amzi\bin) to ...Apache Tomcat X.X\webapps\amzi\WEB-INF\classes.
Alternatively, you can load these libraries (and LSXs) explicitly in Java
with Runtime.getRuntime().load(libraryPath) or loadLibrary(libraryName).
- Copy the amzi/ls subdirectory tree (from amzi\lsapis\java20) to ...Apache
Tomcat X.X\webapps\amzi\WEB-INF\classes
- Stop and restart Tomcat
- In your browser type, http://localhost:8080/amzi/Hello. Enter '\\...Apache
Tomcat X.X\\webapps\\amzi' when prompted for the directory with hello.xpl
in it.
JRUN
In order to run this servlet under JRUN (where X.X is replaced by the
version of JRUN you running):
- Make sure that amzi.dll and amzijni.dll are on the system PATH. (They are
both located in the amzi\bin directory). Alternatively, you can load these
libraries (and LSXs) explicitly in Java with Runtime.getRuntime().load(libraryPath)
or loadLibrary(libraryName).
- Copy the amzi\ls directory tree from amzi\lib\java20 to jrun\X.X\classes.
- Copy Hello.class to jrun\X.X\jsm-default\services\jse\servlets (or
whatever directory you use to hold your servlets under JRUN).
- In your browser type, http://localhost/servlet/Hello
References
See the Java Tutorial to learn How
to Write Servlets.
To learn about configuring servlets under Tomcat, see the Java
Tutorial Lesson on Running Servlets.
For information on how to install and run Tomcat under IIS and Windows see
How
To Setup TOMCAT 4.0.1 on Windows 2000 with IIS and NT Service