Pets JSP Sample
This example adopts the very simple pet identification system to Java Server Pages.
The source code is in:
- PetsJSPBean.java - This Java bean encapsulates calling the Amzi! Logic
Server to load pets.xpl and get the animal type from the sound it makes.
- PetsJSP.jsp - The Java Server Page that invokes PetsJSPBean.class.
- pets.pro - The logicbase that identifies a pet from its sound.
Building the Sample
To build the sample:
- Build pets.xpl by compiling and linking pets.pro.
- Change the pathname in the call to ls.Load to match your webserver (see
below).
- Build PetsJSPBean.class by compiling PetsJSPBean.java with javac
- Organize the files into the proper directories for your JSP/web server
software. You will also need to put amzi.dll and amzijni.dll (Windows) or
libamzi.so and libamzijni.so (Unix) where the JSP/web server can find it.
Running the Sample
Tomcat
Tomcat generally installs in a directory named Apache Group/Tomcat X.X.
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 Group/Tomcat X.X/webapps named
'amzi' (or use another name like amzi1 if you already have an amzi subdirectory).
- Copy the amzi/samples/internet/jsp/pets/WEB-INF subdirectory tree to ...Tomcat
X.X/webapps/amzi.
- Create a directory named 'pets' under the 'classes' subdirectory resulting
in ...Tomcat X.X/webapps/amzi/WEB-INF/classes/pets.
- Copy PetsJSPBean.class to ...Tomcat X.X/webapps/amzi/WEB-INF/classes/pets.
- Copy pets.xpl to ...Tomcat X.X/webapps/amzi
- Copy amzi.dll, amzijni.dll (from amzi/bin) to ...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 entire amzi/ls subdirectory tree (from amzi/lsapis/java20) to ...Tomcat
X.X/webapps/amzi/WEB-INF/classes (so you now have the Logic Server
.class files in Tomcat X.X/webapps/amzi/WEB-INF/classes/amzi/ls).
- Stop and restart Tomcat.
- In your browser type, http://localhost:8080/amzi/PetsJSP.jsp. Enter a sound,
e.g. 'woof' when prompted.