Recently I had to map a servlet as a "welcome-file" in my servlet 2.4 web.xml. This should be straightforward, however I couldn't get it to work for quite awhile. The cause of the problem turned out to be obvious, but rather annoying, in retrospect...
I'm using Stripes as the java MVC framework, which involves a simple configuration in the web.xml to enable the stripes servlet to handle certain paths. Also, I'm using Jetty in my dev environment as a light-weight java servlet container. In production I'm using Tomcat. This turned out to be the source of the problem. The code for the web.xml is below:
.... StripesDispatcher net.sourceforge.stripes.controller.DispatcherServlet 1 StripesDispatcher /home/* .... home
So this all looks ok, yeh? The welcome file is specified as a string that should match the servlet-mapping's url-pattern. The request would get forwarded to the StripesDispatcher servlet which will then eventually get handled by the correct ActionBean. The spec for the web.xml is defined at the top in the web-app tag as being of the servlet 2.4 spec which supports mapping servlets as the welcome-file. Also, both the version of jetty and Tomcat that I was using implement the servlet 2.4 spec.
However, upon loading up my application in jetty and navigating to application in a browser, jetty simply gave me a directory listing. It was clear that the welcome-file mapping wasn't working. At first I thought I got something in the web.xml wrong. After scanning many many articles and discussions on the web about mapping the welcome-file to a servlet I eventually determined that there was absolutely nothing wrong with my configuration.
Basicly, the problem is described by this document on the jetty wiki.
I had assumed that, as long as the servlet 2.4 spec was specified, then this particular feature of servlet 2.4 should be enabled by compliant
containers. Turns out that you need to turn it on in Jetty as it is turned off by default. Brilliant. Why would they do this when
the 2.4 spec says that welcome-file now supports servlet mapping? Bizarro ... but it wasted enough of my time mucking around with my code
when there was nothing wrong with it in the first place ... Naturally, when I deployed my app to Tomcat the welcome-file forwarding to the Stripes
servlet worked by default
oh well ...
Comments ...