1.0          Other languages

3.3.5 Web request dispatcher URL management


In VelocityWeb, URL is always like http://<server_ip>:<server:port>/<web_app_name>/<url_mapping_path>/ControllerServlet?m1=system&m2=store_main

In this URL, the last part


is managed by URL manager in VelocityWeb. To build this URL, first, we need to register "system" to root URL depository.

public class PetStoreController extends SimpleController {
    public boolean initApplication() {
        // add system dispatchers

And the "m1=system" stands for SystemDispatcherGroup, "m2=store_main" stands for StoreMainDispatcher.

public class SystemDispatcherGroup extends DispatcherGroup {
        DispatcherTreeManager.addParentChildrenRelationship(SystemDispatcherGroup.class, StoreMainDispatcher.class);
    public SystemDispatcherGroup() {
        this.setPageLayout(new VPetStorePageLayout());

    public String getUrlId() {
        return "system";


public class StoreMainDispatcher extends QueryDispatcher {
    public String getUrlId() {
        return "store_main";
    public StoreMainDispatcher() {
this.setPageTitle("Default Store Home");
} ...

In this way, this kind of URL can stand for LeafDispatcher and DispatcherGroup.


The max level of this tree in VelocityWeb is unlimited. That means you can create your URL like

In most application, the URL tree level is less than five.

The reason why we don't use the XML file to mapping URL id to dispatcher class is that, when we use single XML file to manage this relationship, it's hard for more than one programmers to concurrent maintain this configuration file. Good design should avoid many programmers modify same file continuously during whole coding phase.

VelocityWeb try to avoid concentrative configuration. As we can see in above code, StoreMainDispatcher specify it's own view HTML page and URL ID inside it. Other dispatcher will do the same thing too. This can avoid one file been concurrent modied by programmers. Because the possibility of concurrent modifying a application level configuration file is more bigger than modifying a request dispatcher class.