Greetings all,
I'm sure this is a newbie problem, but a search of the archives didn't reveal what I
was looking for.
It's probably easiest if I first describe what I want to accomplish:
Mac OS X Server 10.3.3
Apache 1.3.29
Tomcat 4.1.24
(a) Deploy a webapp directory (or .war) that contains Java classes, some JSP pages,
and a web.xml file.
(b) Have the JSP pages execute in the Context of the above web app. Specifically,
access the Java beans contained in the WEB-INF/classes directory and read
configuration parameters defined in the WEB-INF/web.xml file.
I'm having problems with (b). I've created, what I think is, a valid webapps
directory complete with WEB-INF/web.xml file and Java classes.
I believe my problem stems from two confounding issues: (1) I'm trying to do this in a
virtual host alongside Apache and (2) I'm a little fuzzy on the relationship between
JSP pages, the JSP servlet, and web app Contexts.
[ Note: I've made a lot of progress since I picked up "Tomcat: The Definitive Guide",
by Jason Brittain & Ian F. Darwin. I was completely lost before I read their book.
Now, I'm merely bewildered. ;) ]
In my server.xml file, I've defined a virtual host (beyond the default one for
'localhost'):
<!-- Virtual host: www.hotelmidnight.net -->
<!-- (jlb 11-April-2004) Added virtual host -->
<Host name="www.hotelmidnight.net" debug="0" appBase="/Users/darkthirty/Sites"
unpackWARs="false" autoDeploy="true">
<!-- this site doesn't use any user authentication -->
<Logger className="org.apache.catalina.logger.FileLogger"
directory="logs" prefix="darkthirty_log." suffix=".txt"
timestamp="true"/>
<!-- Context for the top-level web application -->
<Context path="" docBase="." debug="99" reloadable="true"/>
<!-- Let's find out if I can use the manager from a virtual host... -->
<Context path="/manager" docBase="/Library/Tomcat/server/webapps/manager"
debug="5" privileged="true">
<ResourceLink name="users" global="UserDatabase"
type="org.apache.catalina.UserDatabase"/>
</Context>
</Host>
Also note that I'm using the default mapping of *.jsp to Tomcat (mod_jk) in Apache,
and *.jsp is mapped to the 'jsp' <servlet> in ${catalina_home}/config/web.xml.
The web application I want to deploy for this site is in /Users/darkthirty/Sites.
I've created a TestBean class in ./WEB-INF/classes. The ./WEB-INF/web.xml file
contains the following:
<web-app>
<display-name>darkthirty</display-name>
<description>darkthirty.net artwork application</description>
<!-- Global parameters for this web application -->
<context-param>
<param-name>test</param-name>
<param-value>Some Value</param-value>
</context-param>
</web-app>
I then wrote a short test.jsp page to check the installation:
<%@ page language="java" import="java.util.*,net.darkthirty.web.art.jsp.*"%><html>
<jsp:useBean id="testBean" class="net.darkthirty.web.art.jsp.TestBean"
scope="application"/>
<head>
<title>JSP TEST PAGE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>TestBean.getProperty(): <%= testBean.getProperty() %></p>
<p>new Date(): <%= (new Date()).toString() %></p>
<p>application.getServletContextName(): <%= application.getServletContextName()
%></p>
<p>application.getInitParameterNames(): <% Enumeration e =
application.getInitParameterNames(); while (e.hasMoreElements()) { %>"<%=
e.nextElement() %>", <% } %></p>
<p>application.getAttributeNames(): <% e = application.getAttributeNames(); while
(e.hasMoreElements()) { %>"<%= e.nextElement() %>", <% } %></p>
<p>config.getInitParameterNames(): <% e = config.getInitParameterNames(); while
(e.hasMoreElements()) { %>"<%= e.nextElement() %>", <% } %></p>
<p>context-param "test": <%= application.getInitParameter("test") %></p>
</body>
</html>
The parts that works are thus:
- If I load the URL <http://www.hotelmidnight.net/test.jsp>, the file test.jsp at
/Users/darkthirty/Sites/test.jsp gets compiled and executed by the JSP servlet.
Here's the output:
TestBean.getProperty(): Hello!
new Date(): Sun Apr 11 21:23:46 MST 2004
application.getServletContextName(): null
application.getInitParameterNames():
application.getAttributeNames(): "org.apache.catalina.jsp_classpath",
"javax.servlet.context.tempdir", "org.apache.catalina.resources", "testBean",
"org.apache.catalina.WELCOME_FILES",
config.getInitParameterNames(): "fork", "logVerbosityLevel",
context-param "test": null
- test.jsp successfully references and instantiates the TestBean object from the class
contained in ./WEB-INF/classes. So it seems that the class loader for this web app is
working.
- If I load <http://www.hotelmidnight.net:9006/manager/html/> it shows that I'm
running two web applications, "/" and "/manager". Loading the test.jsp page causes
the number of sessions in the "/" application to change.
But here's the part that doesn't work:
- The call to application.getInitParameter("test") doesn't return the value for the
'test' context-param I defined in my web.xml file.
- The call to application.getServletContextName() returns null.
- The call to config.getInitParameterNames() returns the properties "fork", and
"logVerbosityLevel". (These are defined in {catalina_home}/conf/web.xml for the 'jsp'
<servlet>.)
All this leads me to believe that my JSP pages are not running the Context of the web
application that I created. They appear to be running in the Context of the 'jsp'
<servlet> defined in ${cataling_home}/conf/web.xml.
When I reload the "/" application in the manager, all of my application scope objects
disappear. So it would appear that the manager is reloading the 'jsp' servlet, not
mine.
Also, the <display-name> of my web app never appears anywhere.
So, what am I missing? How do I deploy a collection of Java classes and a web.xml in
a virtual host's directory so that the JSP pages in that site run in the <Context> of
that web application? I'm eventually going to create other virtual hosts, and I want
the JSP pages in each host to run in their own Context, with the ability to control
and reload them individually.
I admit that I'm dubious about the web.xml I created for my "application" because it
doesn't declare a <servlet>. But my problem is that I don't really have a servlet --
just some JSP pages. Do I need to create a dummy servlet to act as a container for my
JSP pages? Do I need to map *.jsp pages in the <web-app>? How do I do this if I
don't have a <servlet> to reference?
I think I'm a little confused as to the relationship between JSP pages, the 'jsp'
servlet, and a web application. Any reading material that might clarify the
relationship between these would be greatly appreciated.
______________________________________________________
James Bucanek <mailto:[EMAIL PROTECTED]>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]