Now this sets up a host running off my local IP address (of course on the server the name will be a FQDN, a URL of the project).
And this is good and well, I can access the program via the IP address 3.xx.xx.xxx (where the x's are my static IP address).
However, if I try to do anything database related it throws a:
2006-08-03 15:25:03,801 [http-8000-Processor24] ERROR com.xxxx.backend.DatabaseUtils - Error trying to connect to database
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
The only reason why I can see this is not bound is because its not finding the context file correctly.
If I change the virtual host to have an appbase of one directory higher like this:
And the lookup code is simply:
Context context = new InitialContext();
DataSource dataSource = (DataSource) context.lookup("java:comp/env/jdbc/CLV");
Any ideas here? Am I missing something obvious in my configuration file?
How do I get this context file to work correctly? I've tried renaming it to "Contact.xml" and putting it in the $CATALINA_HOME/conf/localhost but this only works for the method of accessing it with "/Contact" on the end.
I've tried adding the <resource-ref> etc. to web.xml, again this only works with the /Contact on the end. How do I get this context.xml to show up if there is no /Contact on the URL?
"The context path of this web application, which is matched against the beginning of each request URI to select the appropriate web application for processing."
Well the problem is my request URI is not going to have the context information in it because we don't want the customer to always have to type the "/ContextName" on the end of it.
So maybe I need to learn how to tell the virtualhost that its always in that context...
Joined: Feb 27, 2006
Had a look at more documentation and still can't figure out what to do or where to start
I'm not sure where to look anymore either, the tomcat documentation doesn't help, nearly every forum post tries to do it a different way (and I can't get any of them to work ). [ August 03, 2006: Message edited by: Gareth Anderson ]
sorry, can't help you with any details... but what i just learnt: whenever you manipulate tomcat configuration, delete the work directory afterwards. otherwise you'll end up with cached (and unchanged) configuration...
Joined: Feb 27, 2006
Sorry, where are you referring to the work directory? And does this apply to tomcat 5.5 (quite different to Tomcat 5.0)
The only conclusion the group came to so far was to do a forward . Other staff members pages on the same server don't have this problem, but they use hibernate which does not require a context.xml to be used in the meta-inf directory.
So I'm the only one trying to do it this way... [ August 05, 2006: Message edited by: Gareth Anderson ]
Joined: Feb 27, 2006
Looks like the only way to do this is to perform a re-direct on the server as the "Contact" in the URL is required for the context to work as expected.
If I was not using a context file then I could have done without the re-direct (or I could use hibernate etc.).
Joined: Feb 27, 2006
Here's the reply I sent to my group about this, I was approaching the problem in the wrong way...
Thanks for those who replied with some advice or assistance about this, I found a way to resolve this and here is some information for anyone else who runs into the same issue.
I was thinking about the problem the wrong way, I was also not interpretting the Tomcat documentation correctly.
From http://tomcat.apache.org/tomcat-5.5-doc/config/context.html it says: "The web application used to process each HTTP request is selected by Catalina based on matching the longest possible prefix of the Request URI against the context path of each defined Context. Once selected, that Context will select an appropriate servlet to process the incoming request, according to the servlet mappings defined in the web application deployment descriptor file (which MUST be located at /WEB-INF/web.xml within the web app's directory hierarchy).
You may define as many Context elements as you wish. Each such Context MUST have a unique context path, which is defined by the path attribute. In addition, you MUST define a Context with a context path equal to a zero-length string. This Context becomes the default web application for this virtual host, and is used to process all requests that do not match any other Context's context path."
Now you *must* have a default Context in a virtualhost if its going to work at all. But if you create a Context file in the META-INF directory as I was trying to do, then it is not going to relate to the default web application unless there is the application name in the URL (which is what I was trying to avoid).
In other words the way of specifying the virutal host was fine, for testing I created a virtualhost from my IP address of my computer, for example:
The above is fine for creating a virtual host but the context will be lost if the webapplication exists under the directory "Contact".
So what I did is create a context file that is default to the host in "C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\Catalina\188.8.131.52", called "context.xml.default" (which is just a copy of the context file in META-INF/context.xml), however this time the context file is for any application on the virtualhost. Since the only application on the virtualhost will be my application there is no problem with this.
Here is the relevant section of the Tomcat manual: "In addition to nesting Context elements inside a Host element, you can also store them:
in the individual $CATALINA_HOME/conf/context.xml file: the Context element information will be loaded by all webapps in the individual $CATALINA_HOME/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host in individual files (with a ".xml" extension) in the $CATALINA_HOME/conf/[enginename]/[hostname]/ directory if the previous file was not found for this application, in individual file at /META-INF/context.xml inside the application files" I'm using the second dot point there, this will work for my particular situation because a virtualhost only runs a single web application, the last dot point did not work for me as I expected, and I don't think the third dot point worked for me either but I haven't had time to re-test this.
Hope that helps someone. Thanks everyone for your help!