Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Vaadin steals all Url Patterns

tom howe
1 decade ago Mar 22, 2011 11:31am
Marko Grönroos
1 decade ago Mar 22, 2011 4:51pm
tom howe
1 decade ago Mar 24, 2011 8:48am
Bobby Bissett
1 decade ago Apr 14, 2011 4:33pm


In case it's not obvious how this works, a url pattern like "/info/a" does not match "/info" but it does match "/*" since the wildcard would match with anything (in this case * == "info/a"). Given two patterns like "/*" and "/info/*", the rule is that the longest match wins, so the second one wins.

I'm currently using Vaadin as the UI front end on a service that provides REST URLs for various things. In my case I wanted to put the web app at /ui and have everything else be for the REST services. But, if a user comes to the main page, I want him/her to be shown the UI. This worked fine for me, and I'm sharing it in case anyone is curious about how the mapping works. A similar pattern, for instance, could be used to map /* to Vaadin but /login.jsp to a JSP if you're using form-based authentication.

In my case, I'm using Java EE 6 so I have the Vaadin mappings in a servlet class like this. The mappings could just as easily be in web.xml:

@WebServlet(urlPatterns = {"/ui/*", "/VAADIN/*"})
    public static class MyServlet extends AbstractApplicationServlet {
        // ...

Then web.xml contains:

        <!-- technically, a JSP is a servlet -->
        <!-- this is the Jersey REST servlet -->

    <!-- We'll map / to the welcome page and /* to our resources. -->

So I have it set up that /* will match to any REST resource I add, as long as it's not /ui/*. When a user first comes to the site, s/he is directed to index.jsp, which is simply:


That's probably a lot more than you want to know, but maybe it will help someone. If the UI is a minor part of the web application, then I like having it sit at a specific URL rather than using /* for it.