Java Server Pages - Programming Experiments
The links listed below refer to the author's initial experiments with Java
Server Pages. For the links to work properly the following requirements have
to be met:
-
a web server with JSP support has to be running on the local host under port
number 9090 (the author is using
Gefion's LiteWebServer 2.2.1
for that purpose);
-
this server has to be configured such that (within the context of these JSP
experiments) it processes *.htm files as JSP documents but delivers
*.html files without any modification (this somewhat strange requirement
comes from a limitation of the author's WYSIWYG HTML editor, which refuses
to handle *.jsp files like HTML documents);
-
all related Java beans and applet files have to be installed in a subdirectory
where they can be found by the server (please note, that all these files
belong to a package called "Acquainting", you may therefore have
to create an additional subdirectory with that name and place all class files
in there). A list of all required files is found at the end of this page.
Please, also consider my "Hints for Reading"
and the "List of Recent Changes".
LiteWebServer Configuration
Proper setup of directories and adequate configuration of the HTTP server
is essential for the JSP experiments to work properly. For that reason, this
section contains any information to "install" these experiments on a
LiteWebServer.
Directory Structure
Within its installation directory, the following files and (sub)folders are
required for the web server to run the JSP experiments (files represented
by a HTML link may be directly downloaded onto your system, other - configuration
- files will have to be modified manually, as described in the next
section):
 |
(LiteWebServer installation directory) |
 |
 |
config/ (LiteWebServer configuration directory) |
 |
 |
 |
server.properties (context for JSP experiments
must be added) |
 |
 |
 |
JSPAcquainting/ (configuration needed for JSP
experiments) |
 |
|
 |
 |
context.properties
(defines servlet context, needs modification) |
 |
|
 |
 |
mime.properties (actually a copy of config/mime.properties) |
 |
|
 |
 |
rules.properties (activates
JSP processing) |
 |
|
 |
 |
servlets.properties
(configures JSP processing) |
 |
|
 |
 |
session.properties (actually a copy of
config/session.properties) |
 |
 |
servlets/ (default directory for servlet class
and data files) |
 |
 |
 |
JSPAcquainting/ (Java class files for the
experiments) |
 |
|
 |
 |
JSP_00_Applet.class |
 |
|
 |
 |
JSP_00_Bean.class |
 |
|
 |
 |
JSP_02_Bean.class |
 |
|
 |
 |
JSP_03_Bean.class |
 |
 |
work/ (the server's JSP working directory) |
|
 |
 |
JSPAcquainting/ (working directory for JSP
experiments) |
All data files (i.e. JSP, HTML and GIF files) for the JSP experiments
reside in the directory configured by
"(installdir)/config/JSPAcquainting/context.properties".
LiteWebServer Configuration
In order to activate the processing of the JSP experiments on this page,
the following two lines have to be added to the file
(installdir)/config/server.properties:
context.JSPAcquainting.confdir=(installdir)/config/JSPAcquainting/
context.JSPAcquainting.uriroot=/JavaServerPages/Acquainting
In both cases, (installdir) has to be replaced
by the access path for the installation directory of LiteWebServer on your
local system.
Additionally, the file
(installdir)/config/JSPAcquainting/context.properties
must be modified as follows:
context.docroot=(docdir)/JavaServerPages/Acquainting/
(docdir) has to be replaced by the access
path for the directory into which any data files (i.e. JSP, HTML and
GIF files) have been copied.
JSP Experiments
After this initial preparation, following the links shown below should work
as foreseen. Please note, that you cannot test the following links over
the internet - you must install a (JSP capable) HTTP server locally (as described
above)!
-
JSP_00
- first experiments with Java Server Pages
(Output Example)
the first "experiment" demonstrates a number of "basic" JSP features such
as
-
insertion of an external file into the current document;
-
evaluation of a Java expression within the HTML code;
-
definition of and access to a ("persistent") variable;
-
instantiation of a JavaBean and access to its parameters and methods;
-
insertion of a Java applet independent of the actual user agent (i.e. web
browser).
The mechanisms shown on that page are rather primitive and have mainly been
used to figure out how to note the various JSP directives and where to place
any required Java class files;
-
JSP_01
- displays the contents of several "CGI variables"
(Output Example)
the second experiment mainly represents an example for a somewhat larger
JSP "scriptlet" which also includes a method that gets called from within
another scriptlet.
Unfortunately, the scriptlet seems to perform extremely poor (it takes approx.
30 seconds to produce a result) - at least, on the author's system (i.e.,
a Pentium III at 650 MHz with 128 MBytes of RAM). You may therefore have
to be patient when visiting this page...
-
JSP_02
- "examines" predefined JSP variables
(Output Example)
JSP_02 examines several predefined JSP variables and writes their contents
into the current HTML document. Because of the performance problems with
JSP "scriptlets", a JavaBean is used instead;
-
JSP_03
- loads an external file and processes it
(Output Example)
this experiment simply demonstrates how to access an external file, process
it and insert the result into a HTML document;
Conclusion
You might have noted the following issues:
-
GIF images will be properly handled on every second JSP request only (probably
because of subtle timing issues)
-
JSP_00 fails to start the embedded applet
-
JSP_03 crashes because of an "Out of memory" error
Because of such bad experiences with Java Server Pages, the author finished
with his experiments at this stage and directed his attention to pure
Servlets again (which turned out
to perform much better).
Required Files
As mentioned above, a few additional files have to be installed for the
experiments to work properly. The following overview lists these files:
Just download these files into the
(docdir) configured above.
Furthermore, you might also be interested in the source code of any Java
applet or JavaBean used for the JSP experiments:
-
JSP_00_Bean.java
an extremely simple JavaBean which is used to demonstrate the access to Bean
variables ("properties");
-
JSP_00_Applet.java
an applet whose invocation tag is automatically created using a
(brower-independent) JSP directive;
-
JSP_02_Bean.java
a simple JavaBean that accepts several predefined JSP variables and writes
their contents into the current HTML document;
-
JSP_03_Bean.java
a simple JavaBean that loads a given (plain) text file, performs some encoding
in order to make the text HTML-compliant and creates a preformatted paragraph
for the result within the enclosing HTML document;
|