Module Servlets
As already mentioned, a module takes its own servlet. Module servlets are defined in the web application's deployment descriptor, which has to be made available as /WEB-INF/web.xml.
For each module, you have to
- define a module servlet; the module name is given by the servlet name.
- pass the context-relative path to the configuration file as initialization parameter config.
-
define exactly one servlet mapping for the module;
a module may be mapped either using
- an extension mapping - this will map request URLs, whose context-relative paths end with some ".ext", to the module - or
- a prefix mapping to map request URLs, whose context-relative paths start with some "/prefix", to the module.
Here's an example web.xml, which uses the modules foo and bar. We'll map prefix /foo to module foo and extension *.bar to module bar:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4">
...
<servlet>
<servlet-name>foo</servlet-name>
<servlet-class>de.odysseus.calyxo.control.ModuleServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/foo/calyxo-control-config.xml</param-value>
</init-param>
<load-on-startup/>
</servlet>
<servlet>
<servlet-name>bar</servlet-name>
<servlet-class>de.odysseus.calyxo.control.ModuleServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/bar/calyxo-control-config.xml</param-value>
</init-param>
<load-on-startup/>
</servlet>
<servlet-mapping>
<servlet-name>foo</servlet-name>
<url-pattern>/foo/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>bar</servlet-name>
<url-pattern>*.bar</url-pattern>
</servlet-mapping>
...
</web-app>
The optional load-on-startup element indicates that this servlet should be loaded on the startup of the web application.
Now, if this application gets deployed under context /sample on http://localhost:8080, then
- the request URL http://localhost:8080/sample/foo/reach?what=stars will select module foo with action path "/reach",
- and request URL http://localhost:8080/sample/walk.bar?where=moon will select module bar with action path "/walk".
It is probably bad practice to have both, prefix-mapped modules and extension-mapped
modules, within one application (as in our example), because this may easily cause
mapping conflicts to occur.
Just consider the URL http://localhost:8080/sample/foo/clash.bar...
which module servlet should be selected by the container?


