I am a newbie with Tomcat and find it very difficult to handle because of all of its features and properties. I would appreciate any guidance to a descent tutorial. I tried using the Tomcat documentation but it wasn't understandable at all because of is technical language.
Specifically I need help with Context element: My application is very simple. It is a single index.html file saved in an absolute directory on my hard drive. (Meaning it is on c:\...\ instead of under CATALINA_HOME directory). I set the localhost Host element to point to that directory and it worked quite well. Next I wanted to enable SSI on this application. The first thing I did was to uncomment the SSI Servlet and the SSI Servlet-mapping inside the web.xml (According to the Tomcat documentation). The next thing I needed to do is to set this Host (localhost) element to be privileged. This is where I couldn't figure out how to continue. I wasn't sure where exactly to place the context.xml file and what to write in it. For simplicity I decided to put a Context element inside the localhost Host element inside server.xml. I tried writing something like this: Which looked the simplest.
Of course that didn't work and I still got an exception when loading Tomcat, telling the SSI servlet is not privileged.
My questions is first to understand exactly what is the Context element and how to use it. Especially what to write in my simple example:
1. What is path attribute? The Context element is inside the Host, so why do I need it?
2. What is the docBase attribute and what to write in it? I am using an absolute path for my application and I am not using a WAR file.
3. What else should I write inside the Context element?
Sorry for the long scroll but as a newbie, I still confused from all the possibilities and features of Tomcat.
However, I think a bigger problem you have is that you don't understand J2Ee itself well enough.
J2EE partitions resources into web applications. Web applications are packed into WAR files, one application per WAR. The exact structure of the WAR is defined by the J2EE specification, and it includes directories such as the WEB-INF/lib and WEB-INF/classes directories.
Tomcat is one of several webapp severs that support what are known as "exploded WARS". An exploded WAR is simply a WAR that has been unzipped into a filesystem directory, You cannot just splatter files all over your disks and have a J2EE webapp. They all have to be related to each other in a directory structure that reflects the original WAR.
When you deploy a webapp, you have to have 2 resources known as "deployment descriptors". One of these descriptors is the WEB-INF/web.xml file and it contains server-independent deployment information defined as part of the J2EE spec. In Tomcat, the other descriptor is the Context, and you can either supply your own or Tomcat will synthesize one from default values.
The Context defines a number of things, one of which is the context root path of the URL. Since Tomcat can host multiple apps concurrently, the context root determines which app will receive a URL request, based on a match between its context root definition and that part of the URL. Warning Context Root path is ignored in certain cases. For example, when you place your Context file in the TOMCAT_HOME/conf/Catalina/localhost directory, the context root in the Context file is ignored under Tomcat 6, and the Context filename itself (minus the ".xml") is used as the context root.
The Context head element also contains a codeBase reference, which defines where the WAR itself is located. This information is ignored when a webapp is deployed to a designated webapp directory such as the TOMCAT_HOME/webapps directory.
Context may be taken from a number of places, in order of ascending precedence:
1. It will be synthesized, if no Context is supplied
2. It will be pulled from the WAR's META-INF/context.xml file if the WAR is copied to TOMCAT_HOME/webapps.
3. It will taken from a TOMCAT_HOME/conf/Catalina/localhost/xxxxx.xml. Make "xxxxx" be the context name you want to use.
4. It will be taken from a Context element in TOMCAT_HOME/conf/server.xml. But don't ever do that!
I'm afraid that the various tricks you've been doing are misuses of advanced Tomcat features. At best, you're substituting cleaner, general-application functions for more arcane, less standardized services. At worst, you could end up digging a very deep hole.
So my recommendation is to study up on the basic J2EE component concepts and read the Tomcat docs.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Sep 30, 2011
Hi, Thanks for the guidance.
Indeed I have a lot to learn about J2EE and Tomcat. The thing is that now I am only at the beginning and all I want to do is to "play" a little with HTML and CSS. For this purpose I only want Tomcat to be the infrastructure for showing simple web pages that don't even contain JS code.
You are right that I should study J2EE more carefully but I want to do it in parallel with client side development.
So at first I would only want to allow Tomcat to process SSI instructions.
Can you explain how to do it correctly?
Do I need to completely change the structure of my app? Meaning, instead of putting it under localhost, should I put it under localhost/app? If so, how do I do it?
Can't I just set some attributes of the context element, even under the Host element (just for now) to allow SSI? All I need for start is to change the context to privileged.