Mounting Servlets

In WEBrick terminology, mounting means setting up an instance of a subclass of HTTPServlet::AbstractServlet a.k.a ``servlet'' to service a request-URI.

When mounting a servlet, one should specify the prefix of the request-URI it services. If there are more than one mounts that match the request-URI, the one with the closest match is selected. For example: a servlet mounted at /foo would probably service the request-URI /foo/bar/is/foolish, but if there is another servlet mounted at /foo/bar, then that servlet would be the one selected instead.

To mount the servlet, specify the mount the path along with the class of the servlet. WEBrick creates a new instance from the servlet class for each request it receives, and executes it in a separate thread.

class FooServlet < HTTPServlet::AbstractServlet
class FooBarServlet < HTTPServlet::AbstractServlet

start_webrick {|server| 
  server.mount('/foo', FooServlet)
  server.mount('/foo/bar', FooBarServlet)