The Invoker
Archive - Originally posted on "The Horse's Mouth" - 2009-02-13 08:47:22 - Graham Ellis
But just occasionally under Tomcat, there's a requirement to be able to copy a Class that contains a servlet on the web server, and have it available straight away - no mucking about with web.xml. For example, I'm training systems administrators who will be looking after a system used by Java classes (University ones, not ours!) this week, and their students need to be able to upload a class that contains a servlet, and with minimal fuss and editing, test it on the server. This is where the Invoker comes in.
To enable the invoker ... in the administrator's main web application configuration file (also called web.xml, but in the conf directory), remove the comments that disable the Invoker in the sample file supplied with the Tomcat distribution. That extra code comes in two sections - one to define what the invoker IS and and other to define how it MAPS - and you need them both. Then kick [restart] your Tomcat.
To use the invoker for a new Servlet ... place the class file in the WEB-INF/classes subdirectory of your web application, and visit it via a URL of the form:
http://www.sitename.org.uk/webappname/servlet/Whichone
where webappname is the name of your web application (directory name in the webapps folder) and Whichone is the class name - i.e. the file is called Whichone.class. The word "servlet" is 'hard coded' in the web.xml file - you can change it server-wide if you wish!
We go through all of this (and much, much more!) on our Deploying Apache httpd / Tomcat course. Illustration - a waiter at Gun Wharf in Portsmouth