Tomcat Tip - host specific web.xml

One of the issues I had with Tomcat is that while I'm running Mango blog on my VPS, not everyone else on my VPS is. So, how do I create 'host' specific servlet-mappings without impacting everyone else on my box? As I was digging into the issue, the answer is at the top of Tomcat's web.xml file (located in { tomcat installation dir/conf/web.xml }:

  <!-- ======================== Introduction ============================== -->
<!-- This document defines default values for *all* web applications -->
<!-- loaded into this instance of Tomcat. As each application is -->
<!-- deployed, this file is processed, followed by the -->
<!-- "/WEB-INF/web.xml" deployment descriptor from your own -->
<!-- applications. -->
<!-- -->
<!-- WARNING: Do not configure application-specific resources here! -->
<!-- They should go in the "/WEB-INF/web.xml" file in your application. -->

I hadn't paid attention to this before. Definitely a 'duh' moment. So, inside my web-rat.com's WEB-INF directory, I created a web.xml file with the following:

<?xml version="1.0" encoding="ISO-8859-1"?>
    version="2.5">
        <servlet-mapping>
       <servlet-name>RailoCFMLServlet</servlet-name>
       <url-pattern>/blog/post.cfm/*</url-pattern>
       <url-pattern>/blog/page.cfm/*</url-pattern>
       <url-pattern>/blog/archives.cfm/*</url-pattern>
       <url-pattern>/blog/feeds/rss.cfm/*</url-pattern>
    </servlet-mapping>
</web-app>

Thanks to Tom King (@Neokoenig) for mentioning the Mango specific filters on the Railo list and prompting me to investigate because I knew that my blog archive wasn't working properly. Now they are. :)

Update: Fixed / condensed XML - had some stuff that wasn't necessary. Also, please note "RailoCFMLServlet" should be whatever the <servlet-name> is that you defined in your Tomcat's web.xml.

Ricardo Parente

Ricardo Parente wrote on 06/17/11 11:51 PM

I'm new to Railo and Tomcat. I installed Mango blog and without the web.xml in the application web-inf folder, I can get the homepage of the blog, but none of the links work, they give me a 404.
I followed your instructions and placed your code (web.xml) in my application's web-inf. Now I get 404 even in the home page. Nothing works.
If I delete the web.xml and restart Tomcat, I get the home page again.
What could be wrong ?
Thanks for your help.
Ryan

Ryan wrote on 07/14/11 5:29 PM

Todd, I am trying to configure clean urls with Railo and cfwheels. I was pointed to your post from the cfwheels list. I added the above to my web.xml but I am still getting a 404 from Tomcat. Do you know of any resources on getting cfwheels clean urls going with Railo?

Leave a comment


(required field)

(required field)