When it receives a request, the web container determine the web component that should handle the request via the url
A URL path contains the context root and, optionally, a URL pattern:
http://host:port/context-root[/url-pattern]
The web container does the mapping
The context root is defined in the web app descriptor
Example: WEB-INF/weblogic.xml (Doc)
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<context-root>/</context-root>
</weblogic-web-app>
You set the URL pattern for a servlet by using the @WebServlet annotation in the servlet source file.
For example, the following annotation specify the URL pattern as /myAlias:
@WebServlet("/myAlias")
public class myServlet extends HttpServlet {
...
This annotation indicates that the URL pattern /myAlias follows the context root. Therefore, when the servlet is deployed, it is accessible with the following URL:
http://host:port/context-root/myAlias
To access the servlet by using only the context root, specify “/” as the URL pattern.