How to Set Default Context Path in Apache Tomcat (Linux)

A context path in Apache Tomcat refers to the name of the website as presented by the browser. For example, imagine I tell you to enter "localhost:8080/DemoWebsite/DateJSP.jsp" in your browser. The context path is "DemoWebsite". The term "context" in Tomcat is in fact synonymous with "website". The default context path can be specified if we provide a context file to Tomcat that is given the same name as the website. In this topic, you will learn how to accomplish this important task.

To learn how to set the default context path in Apache Tomcat in a Linux environment, follow these 9 steps:

  1. Create a folder named DemoWebsite under the root (i.e., / ) of the file system.
  2. You will need to store DateJSP.jsp in this folder. This file was created in the following topic: Click here to learn how to run a JSP program in Apache Tomcat (Linux)
  3. In your text editor, you will develop a context file. Context files are composed of XML statements. Type the following statement in a new file:
    <Context path="/Placeholder" docBase="/DemoWebsite" />
    The context path will be determined by the name of the file, not the path attribute value. The path attribute is only used by Tomcat if a context is placed in server.xml.
  4. Save your file as /DemoWebsite/DemoWebsite.xml. This is not a required location, but will prove convenient for referencing the file in the future.
  5. Copy the XML file to CATALINA_BASE/conf/Catalina/localhost, e.g., /var/lib/tomcat7/conf/Catalina/localhost.
  6. Start the Tomcat server.
  7. Start your browser if it is not already running.
  8. In the address area of the browser, type http://localhost:8080/DemoWebsite/DateJSP.jsp and submit that address to the browser.
  9. The output of your JSP page will be displayed:
    Date JSP
Author: Stephen Withrow

Stephen has over 30 years of experience in training, development, and consulting in a variety of technology areas including Python, Java, C, C++, XML, JavaScript, Tomcat, JBoss, Oracle, and DB2. His background includes design and implementation of business solutions on client/server, Web, and enterprise platforms. Stephen has a degree in Computer Science and Physics from Florida State University.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.