Workshop: Deploying Java Server Pages on Apache
October 23, 2000
By Lori MacVittie
Setting up JSPs
To setup JSPs, we copied the default properties file, zone.properties, and created a new file called test.properties. You'll need to make a change to the repository listing. The repositories directive indicates the jar files or directories containing servlets which are controlled by this zone.
repositories=/home/gnujsp-1.0.0/lib/gnujsp10.jar
repositories=/home/gnujsp-1.0.0/lib/servlet-2.0-plus.jar
You should also include the gnujsp jar files here. All that is left is to define the gnujsp servlet and specify it's init paramters. This is accomplished by including the following within test.properties :
servlet.gnujsp.code=org.gjt.jsp.JspServlet
servlet.gnujsp.initArgs=jserv=true,checkclass=true,pagebase=/var/www/html,
scratchdir=/usr/local/apache/jsp,debug=true,compiler=builtin-javac -classpath
%classpath%:%scratchdir%:/home/gnujsp-1.0.0/lib/servlet-2.0-plus.jar:/home/gnujsp-1.0.0/lib/gnujsp10.jar
-d %scratchdir% -deprecation %source%
Be sure that pagebase points to the DocumentRoot of your Web server and that scratchdir points to a directory that the JVM process can write to.
That's it! Now restart Apache and test your installation.
Test It Out
There are several .jsp files included with the gnujsp distribution. snoop.jsp (this lists environment and agent variables), hello.jsp (of course), and date.jsp. Post them so that they are accessible from the Web server. We created an "examples" directory in the root of our Web server and copied all the .jsp files there.
You should now be able to access any of these JSP files via a URL like this:
http://mydomain.com/examples/hello.jsp
If everything worked correctly, you should see the following text.
The Famous JSP Hello Program
The following line should contain the text "Hello GNUJSP World!".
If that's not the case start debugging ...
 Hello GNUJSP World!
Debugging
If everything did not go as planned, you can try several things to find the problem. In jserv.conf you can change the level of information being shown in the log file. You can also change the ApJServLogLevel directive so that it displays more informative information.
Our first installation failed miserably. We could run servlets some of the time but not others. After expanding the level log information, we found the following error to be particularly confusing:
(INFO) wrapper: VM died too many times w/in 5 second intervals (6);
no more tries
After consulting the FAQ-O-MATIC (http://java.apache.org) we found that this is generally caused by the JVM's inability to write to or read a log file. We verified that permissions were correct and remained mystified for several hours.
After a while, we found that the problem was the time-out length specified in the jserv.conf file. Our first installation was on a P-II 75 machine running RedHat 6.2 with 16 MB of RAM. It is commonly accepted that there be a limit of 125 users per JVM, 256 MB RAM per JVM, and 250 MHz of CPU per JVM. We were no where close to the minimum recommendations, so the JVM was timing out while trying to process each call. We increased the ApJServVMTimeout from its default of 10 seconds to 30 seconds, and suddenly we were running smoothly. Not quickly, but smoothly.
The JSP specification is based on XML and therefore requires JSP documents to be well-formed. Fortunately, errors caused by pages containing malformed tags will be displayed in the browser when you attempted to run them. This aided in quick debugging the problems associated with incorrect JSP syntax.
Using JSPs on a lower-end machine causes performance problems as well. This is because the performance is directly related to the capabilities of the JVM you invoke to process and compile your JSP files. If you're experiencing such problems, you can try two things. First, you can upgrade your machine. However, since this is often not an option, you can try IBM's Jikes compiler, purported to be much more efficient and a better performer than Sun's compiler.
Even though we ran into problems, most of them were solved by carefully reading the documentation included in the property files or by consulting the FAQ. By following the installation instructions carefully, you should be able to get JSP support up and running without too many roadblocks.
If you have any comments on or questions about this article, please message Lori MacVittie at lori@nandgate.com.
Page 1 | 2 | 3 | First page
|