You can compile a Kawa program to a Servlet, and run it in a servlet engine (a Servlet-aware web server). One or more servlets are installed together as a web application. This section includes specific information for the Tomcat and Glassfish web servers.
A web application is a group of data, servlets, and configuration files to handle a related set of URLs. The servlet specification specifies the directory structure of a web application.
Assume the web application is called
myapp, and lives in a
directory with the same name. The application normally handles
requests for URLs that start with
Most files in the application directory are used to handle
requests with corresponding URL. For example,
myapp/list/help.html would be the response
to the request
WEB-INF is special. It contains configuration
files, library code, and other server data.
So to create the
myapp application, start with:
mkdir myapp cd myapp mkdir WEB-INF WEB-INF/lib WEB-INF/classes
Copy the Kawa jar from the
(You can also use a “hard” link, but symbolic links may not
work, for security systems.)
You should also create the file
For now, this is is just a place-holder:
<web-app> <display-name>My Application</display-name> </web-app>
Assume for simplicity that the source files
are in the
WEB-INF/classes directory, and make that the
Depending on the source language, you compile your script
kawa --servlet -C hello.scm
kawa --servlet --krl -C hello.krl
kawa --servlet --xquery -C hello.xql
This lets the web-application find the compiled servlets.
Finally, you just need to add the new servlet to
<web-app> <display-name>My Application</display-name> <servlet> <selvlet-name>MyHello</servlet-name> <selvlet-class>hello</servlet-class> </servlet> <servlet-mapping> <selvlet-name>MyHello</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> </web-app>
<servlet> clause says that the servlet named
MyHello is implemented by the Java class
<servlet-mapping> clause says that a request
/hello should be handled by the servlet named
The URL is relative to the application context path,
so the actual URL would be
To install your web application, copy/move its directory
to be in the
Thus for the example above you would have
To start or stop Tomcat use the scripts in
For example to start Tomcat on a GNU/Linux system run
$CATALINA_HOME/bin/startup.sh. This will start a web server
that listens on the default port of 8080,
so you can browse the above example at
If you’re running Fedora GNU/Linux, you can use the
# yum install tomcat6 # export CATALINA_HOME=/usr/share/tomcat6
You can the manage Tomcat like other system services.
You can install webapps under
Glassfish from Oracle/Sun
is a open-source “application server” that implements
Java EE 6, including the 3.0 servlet specification.
After you download it, uncompress it in some convenient location.
This location is called
as-install-parent in the
Quick Start Guide.
The commands you will use is most in
To start the server, do:
or under under Windows:
The default post to listen to is
you can the port (and lots of other properties)
using the adminstration console at port
A web application does not need to be any particular location, instead you just install it with this command:
appdir is the application directory -
myapp in the example.
asadmin.bat under Windows.)
The following functions only work within a servlet container. To use these functions, first do:
You can conditionalize your code to check for servlets, like this:
(cond-expand (in-servlet (require 'servlets) (format "[servlet-context: ~s]" (current-servlet-context))) (else "[Not in a servlet]"))
When called from a Kawa servlet handler, returns the actual
Returns the context of the currently executing servlet, as an instance of
ServletConfigof the currently executing servlet.
Return the current servlet request, as an instance of
Return the current servlet response, as an instance of
Get the servlet path of the current request. Similar to
request-script-path, but not always the same, depending on configuration, and does not end with a
Get the path info of the current request. Corresponds to the CGI variable
Returns the file path of the current servlet’s "Web application".