I probably should not be replying, as I am certainly no expert on this. But here goes…
I suspect you are ignoring the concept of the “Context”. Your servlet operates within part of the URL, the “context path”.
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
By default, if you create a Vaadin app, export it as a WAR file, and then move it to a web server like Tomcat, the WAR gets automatically deployed which includes re-hydrating or expanding the WAR file back to a folder. That WAR file name (and folder name) defines the context, by default in Tomcat.
For example, I create a Vaadin app called “AcmeInvoices”. I export a “AcmeInvoices.war” file. I drop that into Tomcat’s “webapps” folder (or in my case, a folder for the “virtual host” web site). The war file gets expanded back to “AcmeInvoices” folder. By the way, when deploying a fresh WAR, you must delete the existing expanded folder too.
If my domain is “acme.com”, then the URL for my app would be:
http://www.Acme.com/AcmeInvoices/
Note that a domain name is case-insensitive. So you can choose to use any variation such as http://www.acme.com/ or http://www.Acme.com/
But the rest of the URL is case-sensitive. So it must be "
/AcmeInvoices/
" to match the WAR file/folder name.
The "
" tag you show in your posting here refers to what appears
after
this first part.
So
refers to the “dog” and “cat” portion of these two URLs:
http://www.Acme.com/AcmeInvoices/dog
http://www.Acme.com/AcmeInvoices/cat
In basic Vaadin apps, we don’t use such URLs with the “dog” or “cat” portions. Therefore, the usual Vaadin servlet-mapping’s url-pattern is:
/*
That says we want URLs with anything (or nothing) after the “/AcmeInvoices” to be handled by our vaadin app.
I let the Eclipse plugin generate my Vaadin app’s “web.xml” file. In there I find this servlet-mapping:
<servlet-mapping>
<servlet-name>Acmeinvoices Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
The ‘i’ of Invoices is lowercase because of the Eclipse Vaadin plugin’s naming conventions. But the important point in this example is the "
" tag.
So why does the url-pattern refer to just the portion after the context name, and not the entire URL? Because the first part of the URL is none of the Servlet programmer’s business. The webmaster defines the URL that makes up the “context” in which your servlet operates. The webmaster can define and change the URL mapping to your servlet without consulting you, and your servlet should keep on working. If your Vaadin app cares about the URL, any such URL should never be hard-coded as you cannot assume what the URL will be at deployment. Defining the context’s URL is not part of the Servlet spec (asfaik) – the context’s URL is up to the implementation of the servlet container (the web server) and the webmaster.
I learned the above info while trying to discover how to change the URL. Instead of my app responding to this URL:
http://www.Acme.com/AcmeInvoices/
I want to use this url:
http://www.Acme.com/invoices/
I don’t yet know the answer, but I believe
in
is the wrong way to go. In the case of Tomcat, I suspect the answer is the
tag (note the uppercase ‘C’). The confusing part is that there are many ways & places & defaults for
.
[Update]
Seems the easy answer is simply rename the WAR file. See
my other Forum thread
.
I hope this helps. But remember my caveat at the top: I may not know what I’m talking about here.
–Basil Bourque