Is it permissible to have multiple entries as the context root of a servlet?
For instance, all Sun examples use a single /catalog
or something similar as the context root, but could it be /catalog/furniture
as well?
The Servlet 2.4 Specification is not specific here.
Context Path: The path prefix associated with the
ServletContext
that this servlet is a part of. If this context is the “default” context rooted at the base of the Web server’s URL name space, this path will be an empty string. Otherwise, if the context is not rooted at the root of the server’s name space, the path starts with a’/’ character but does not end with a’/’ character.
WE can't give multiple context root to a servlet. But we can change dynamically with different names in server.xml
as
<web-uri>Project.war</web-uri>
<context-root>myproj</context-root>
We can configure our project context root with different names but it should be one name.
By default if you call contextPath using request object as req.getContextPath();
it will get by default with slash(/) as /myproj
.
For more info to change context roots as static to dynamic you can check here.