Servlets

Register servlet by URL pattern

public void registerServlet( Servlet servlet, String[] urlPatterns, Dictionary initParams, HttpContext httpContext ) throws ServletException
Registers a servlet.

servlet

The servlet object to register

urlPatterns

An array of url patterns this servlet maps to. Cannot be null.

initParams

Initialization arguments for the servlet or null if there are none. This argument is used by the servlet's ServletConfig object.

httpContext

The HttpContext object for the registered servlet, or null if a default HttpContext is to be created and used

Throws

ServletException — if given servlet object has already been registered

Throws

IllegalArgumentException — in the following situations:

  • servlet is null
  • urlPatterns is null or empty

To give a name to the registered servlet you can add an element named servlet-name to initParams and as value the servlet name.

(warning) Starting from 0.5.2, Servlet registration can accept servlet name as a direct parameter. See here.

(info) starting with 1.1.4 it's possible to filter init parameters. As shown in WebExperience it's now possible to configure the init.parameters for the servlets and filters with the prefix init.
For background info take a look at here

Unregister a servlet

public void unregisterServlet( Servlet servlet )
Unregisters a previously registered servlet.

servlet

The servlet to be unregistered

Throws

IllegalArgumentException — if:

  • servlet is null
  • the servlet is unknown to Web Container (never registered or unregistered before)

Content