Java Web Application - Mapping URLs to Web Components (context-root, url pattern)

Java Conceptuel Diagram


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:


The web container does the mapping

  • between the URL path and a web application via the context-root
  • between the URL path and a servlet via the url-pattern


Setting the context-root

The context root is defined in the web app descriptor

  • Glassfish: sun-web.xml;
  • JBoss: jboss-web.xml;
  • Weblogic: weblogic.xml;
  • Tomcat: context.xml;
  • WebSphere: ibm-web-ext.xml.

Example: WEB-INF/weblogic.xml (Doc)

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="">

Setting the URL pattern

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:

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:


To access the servlet by using only the context root, specify “/” as the URL pattern.

Discover More
Java Conceptuel Diagram
Java - Web Application (Web Module) - War

Web application in Java. A Java web application serve and/or generates interactive HTML web pages. An enterprise application may contain zero or more web applications. A web application is generally...
Weblogic Index Static Website
Weblogic - Static Web Site Deployment

in Weblogic How to deploy a static website in Weblogic. create a WEB-INF directory at your web site root add a web.xml in this directory add also the weblogic.xml file that defines the context-root...

Share this page:
Follow us:
Task Runner