Saturday, November 21, 2009  
Google
Web pcquest.com

CIOL Network sites

Search by Issue | Sitemap | Advanced Search

• For most updated version of DQ TOP 20 issue, visit dqindia.com • Ad : Play and Plug ERP by IBM

Home > Linux > Customizing Tomcat

    Enterprise Solutions
    Hands On
    ITstrategy

    Developer

    Tech Forum

    SMB Forum

    Trends

    Shootout

    Reviews
    Editorials
    Linux and Open Source
    Technology
    Extraedge

    IT Careers

    Vertical Focus

Subscribe to Print magazine.


now!


Newsletter


Customizing Tomcat

How to locate your JSPs in a new directory on this JSP engine
Shekhar Govindarajan

Sunday, May 06, 2001

In this article, we’ll see how to customize Tomcat. We’ll use the JPSs that we wrote in Write Your Own JSP Script, page 144 in this issue, place them under the directory /home/httpd/html/jsp, and make Tomcat aware of this new location, called context in Tomcat lingo. Contexts are defined in the file server.xml found in tomcat/conf directory. Open this file in a text editor and go to the section named ‘Special webapps’. Here you can find the examples context:

<Context path=”/examples”
docBase=”webapps/examples”
crossContext=“false”
debug =“0”
reloadable=”true” >
</Context>

The two important attributes to understand are ‘docBase’ and ‘reloadable’. With docBase you can specify a directory relative (as above) to the Tomcat directory or an absolute path like /home/httpd/ html/jsp. If the reloadable attribute is set to true, Tomcat will reload JSP on each request, a feature that can be used for testing. Obviously, reloading the JSP each time increases execution time. The ‘debug’ attribute can be used to increase the amount of debugging information shown.

Now below these append the following lines, where we define a context named ‘/jsp’ as:

<Context path=”/jsp”
docBase=”/home/httpd/html/jsp”
reloadable=”true” >
</Context>

If you have set up Tomcat to run as standalone, then you just need to shutdown and restart it. Create the directory ‘jsp’ under /home/httpd/html and place the file jspprogram.jsp in it. Now execute the JSP in the browser using the URL:

http://localhost:8080/jsp/jspprogram.jsp

If you have set up Tomcat as an Apache module, you must tell Apache to send all the files, with JSP extension, found in /home/httpd/html/jsp directory to Tomcat. Also we must mount the /jsp context using ApJServMount directive. These changes are to be made in the tomcat.conf file that we created in /etc/httpd/conf directory last month. After the changes tomcat.conf file will look like:

LoadModule jserv_module modules/mod_jserv.so
<IfModule mod_jserv.c>
ApJServManual on
ApJServDefaultProtocol ajpv12
ApJServSecretKey DISABLED
ApJServMountCopy on
ApJServLogLevel notice
ApJServDefaultHost localhost
ApJServDefaultPort 8007
Alias /examples /opt/tomcat/webapps/examples
Alias /jsp /home/httpd/html/jsp
<LocationMatch /examples/*.jsp>
SetHandler jserv-servlet
</LocationMatch>
<LocationMatch /jsp/*.jsp> SetHandler jserv-servlet </LocationMatch>
ApJServMount /examples/servlet /examples
ApJServMount /jsp
</IfModule>

The first line LoadModule jserv_module modules/mod_ jserv.so loads the module mod_jserv.so for Apache, which we got by compiling the Tomcat sources (See Tomcat on Linux, page 105, PCQuest April 2001) from the directory modules (a subdirectory in /etc/httpd). The path specified here is relative to /etc/httpd directory. If the module loading was successful, which is checked by the line <IfModule mod_jserv.c>, the statements between this line and the line </IfModule> are executed. 

The next four lines have to be left at default. The line ApJServManual on means that the Tomcat engine must be started manually (we do this by executing startup.sh). The line “ApJServDefaultProtocol ajpv12” specifies the protocol being used by Tomcat. “ApJServSecretKey DISABLED” disables the exchange of a secret key between Apache and Tomcat for security. This exchange has not been implemented. “ApJServMountCopy on” is used in case of virtual hosting. 

The line ApJServLogLevel notice specifies the amount of debugging information Tomcat will show. Apart from the default log level, notice, the other  log levels are emerg, alert, crit, error, warn, info  and debug. 

The next two lines ApJServDefaultHost localhost and ApJServDefaultPort 8007 specify the machine address and port on which Tomcat is running. The ApJServDefaultHost can be used if Apache Web server and Tomcat are running on different machines. 

The changes have been shown in magenta color. Here, we first we define an alias /jsp for the directory /home/httpd/html/jsp. Next using the <LocationMatch> tag we instruct Apache to send all files with a JSP extension in the /home/httpd/html/jsp directory to the jserv-servlet handler (that is, Tomcat). Finally we mount the /jsp context as: 

ApJServMount /jsp

Mounting the context can be thought of to be similar to mounting filesystems in Linux. We do this so that the Tomcat module for Apache can be aware of the new context. Make sure to copy the file jspprogram.jsp in /home/httpd/html/jsp. Now you must stop and restart Tomcat as well as Apache using the following commands:

/opt/tomcat/bin/shutdown.sh
/opt/tomcat/bin/startup.sh
/etc/rc.d/init.d/httpd/restart

Now you can run the jspprogram.jsp with the URL 

http://localhost/jsp/jspprogram.jsp

Shekhar Govindarajan


Page(s)   1   

End of the article

PC Problems? Get a solution in 24 hours. Ask Tech Expert




Untitled Document



ZTE:Leading CDMA Technology


Extraordinary Networks:Freedom of Choice


Message boards

Discuss this and many other IT topics at the
CIOL message board

Previous Stories

Winux and Lion

The Latest X Server

Tomcat on Linux

   
 

 
 

Magazine Subscription | RQS | Contact Us | Team PCQuest | Advertising - Print | jobs@cybermedia