Java Servlets - Server Side Java

Jazz home
>
Papers & Training
Server side Java with
Apache/iX
» Return to original page
(please notice that I am only
tasting
software, not
testing
it ;-)
When I recently played with a trial version of Java Web Server from Sun (on MPE/iX, of course), I
learned a little bit about the concept of Servlets for implementing server side functionality in Java. I
found the servlet technology and associated API quite interesting, not just because of its underlying
concept and architecture, but also because it allowed me -still a Java beginner- to implement a few
examples of using server side Java to generate dynamic web pages with amazingly small effort. So I
thought, I'd write up this little piece to share some of the experiences with you. Last, but not least,
because it also can be used with Apache/iX - but we'll cover that later.
What the h*** is a servlet?
A servlet is basically a user-supplied extension of the web server's default functionality. Like an
Applet is a piece of Java bytecode that is executed inside the web browser to implement some
functionality on the client side, a Servlet is a piece of Java bytecode that is executed inside the web
server to implement some functionality on the server side. In typical cases it would be used to
generate web pages with dynamic content on-the-fly or provide some web interface to a server side
application.
The servlet technology is just another means to avoid the classic CGI child process implementation
and its associated overhead for short-lived process creation as well as hassle
with state management
to make a sequence of inherently independent http requests form some kind of logical transaction
from the user perspective.
The Java Web Server invokes a Servlet for handling selected http requests. It simply calls the
appropriate method from the Servlet API, passing parameters that give access to the http request
data (like
QUERY_STRING
,
PATH_INFO
, cookies, or input fields of an HTML form) as well as allow
sending a response back to the client. This does not involve a child process creation, it is just a kind
of subroutine call, if you a allow me this non-object oriented term here. Just like the QWEBS web
server, for example, can call a user-supplied COBOL subroutine from an XL. The servlet code is
loaded and initialized once and then stays alive for handling multiple requests (with the option of
multi-threading for concurrent requests).
Where does Apache/iX come into play?
Unlike the Java Web Server from Sun, Apache is not written in Java and thus cannot simply call a
Java "subroutine" (without invoking some kind of Java Virtual Machine first). But do not despair, we
live in freeware land here! There is a project called JServ for Apache, that essentially brings Java
Servlet capabilities to this popular web server.
The implementation is quite similar to FastCGI (in case you should know that other interesting
technology) i.e. the Apache server is enhanced with a mod_jserv module which allows the httpd
server processes to talk to a JServ servlet engine using a TCP connection. The servlet engine is
written in Java and
handles the servlet loading and invocation. You can run one or more JServ
engines on different TCP port numbers or even different machines! So you can, for example run the
Apache web server on Unix or Linux or NT (if you should feel a need to do so, for example for load
balancing, independent hardware scaling, network isolation or whatever reason) and the JServ
application server on MPE/iX, where the data lives.
It might even be possible to use Stronghold, the commercial "Apache with strong encryption SSL", in
such a setup... (but I haven't tried).
The nice thing about Apache and JServ is that they both
build on MPE/iX "out of the box"! Believe me
that it was a pleasant surprise for me to download Apache 1.3.4 from www.apache.org and JServ
Page
1
of
3
Server side Java with Apache/iX
7/18/2008
http://www.hp.com/cgi
-
bin/pf
-
new.cgi?IN=http://jazz.external.hp.com/papers/java/index.h
...