Sometimes you just want to enable a directory on your tomcat server to be able to run JSP pages without actually installing a WAR or EAR file. Here are the essential steps to enable a directory to execute JSP files.
For this example, I'm setting it up on a SuSE Linux system so your directory structure may vary.
- Create a JSP directory in your tomcat webapps directory. In this case, the default webapps directory for Tomcat is
/srv/www/tomcat5/base/webapps/
so I make ajsp
directory there. - Under the
jsp
directory I create the basic webapp directory structure and create a directory named/srv/www/tomcat5/base/webapps/jsp/WEB-INF
- In the
WEB-INF
directory, I create a basic deployment descriptor namedweb.xml
which looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<display-name>My JSPs<display-name>
</web-app> - In the tomcat configuration directory
/etc/tomcat5/base/Catalina/localhost
add the context path for the JSPs in a file namedjsp.xml
that looks like:
<Context path="/jsp" docBase="jsp"
debug="0" reloadable="true" /> - Restart Tomcat (
rctomcat5 restart
) - Create some sample JSP file in the jsp directory (
/srv/www/tomcat5/base/webapps/jsp
such as:
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1><%= "Hello World" %><h1>
</body>
</html> - Make sure it's working via
http://localhost:8080/jsp/index.jsp
- I run Tomcat under Apache via mod_jk so that I can utilize the SSL layer of Apache. So, to make the JSP transparently accessible from Apache, I update the
/etc/apache2/conf.d/jk.conf
and add the following lines:
# Add the jsp directory
Alias /jsp "/srv/www/tomcat5/base/webapps/jsp"
<Directory "/srv/www/tomcat5/base/webapps/jsp">
Options Indexes FollowSymLinks
allow from all
</Directory>
JkMount /jsp ajp13
JkMount /jsp/* ajp13
<Location "/jsp/WEB-INF/">
AllowOverride None
deny from all
</Location> - After restarting Apache (
rcapache2 restart
) I can then reference the JSPs directly from Apache, such ashttp://localhost/jsp/index.jsp
No comments:
Post a Comment