7.3. Context Root

The context root determines the URL of a deployed application. By default, the context root is identical with the application directory or archive structure; for example, if you deploy an application.war archive, which contains JSP pages in a hello directory, the JSPs in the hello directory will be available under /application/hello/.

Procedure 7.2. Rewriting the Default Context Root

You can change the context root if required. To rewrite the context root, you need to define the new context root and allow the server to use the new context.
  1. To define a new context root, add the context-root element with the new value to the deployment descriptor of the application:
    • To change the context root of a web application, add the context-root element to the jboss-web.xml file.

      Example 7.3. Example jboss-web.xml with a context root defined

      <?xml version="1.0"?>
      <jboss-web>
         <context-root>/application-root</context-root>
      </jboss-web>
      The URL address for the application on localhost is

      http://localhost:8080/application-root

    • To change the context root of a servlet, change the url-pattern element in the web.xml file.

      Example 7.4. Example web.xml with a context root defined

      <?xml version="1.0"?>
      <servlet-mapping>
        <servlet-name>MapRenderer</servlet-name>
        <url-pattern>/servlet-root</url-pattern>
      </servlet-mapping>
      The URL address for the servlet on localhost is

      http://localhost:8080/application-root/servlet-root

  2. To start the server with the REWRITE_CONTEXT_CHECK variable set to false, run the following command: run.sh -Dorg.apache.catalina.connector.Response.REWRITE_CONTEXT_CHECK=false