How do I hit a servlet without a web.xml servlet mapping?
Author: Deron Eriksson
Description: This tutorial describes how to use the InvokerServlet to hit a servlet without a servlet mapping.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 2.0 (Eclipse 3.3.0) || Tomcat 5.5.20


In Tomcat's conf directory (in this example, C:\apache-tomcat-5.5.20\conf), TomcatSW has a default web.xmlW that applies to all web applications. By default, the InvokerServlet and its mapping are commented out. If you uncomment them, it is possible to use the InvokerServlet to hit servletsW without a servletW mapping in your web application's web.xml file.

The uncommented conf\web.xml entries are shown here:

...
    <servlet>
        <servlet-name>invoker</servlet-name>
        <servlet-class>
          org.apache.catalina.servlets.InvokerServlet
        </servlet-class>
        <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
...
    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>
...

If we fire up a web application in Tomcat, we can how hit a servlet by the InvokerServlet, as shown here:

Hitting servlet in web browser via InvokerServlet

The servlet is invoked via the /servlet/ mapping followed by the full package/class name of the servlet. In this example, the full name is com.cakes.TestServlet.