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

See Apache: Tips and Tricks for similar articles.

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.

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

Written by Stephen Withrow

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

  1. Create a folder named DemoWebsite under the C drive (or another drive letter).
  2. You will need to store DateJSP.jsp in this folder. Click here to learn how to run a JSP program in Apache Tomcat (Windows) and create the file needed in this step
  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="c:/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 c:/DemoWebsite/DemoWebsite.xml.
  5. Copy the XML file to CATALINA_BASE/conf/Catalina/localhost, e.g., c:/Tomcat8/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

Related Articles

  1. How to Start and Stop Apache Tomcat from the Command Line (Windows)
  2. How to Deploy a WAR File to Apache Tomcat (Windows)
  3. How to Start and Stop Apache Tomcat from the Command Line (Linux)
  4. How to Deploy a WAR File to Apache Tomcat (Linux)
  5. How to Run a JSP Program in Apache Tomcat (Windows)
  6. How to Check the Status of the Apache Tomcat Server (Windows)
  7. How to Deploy a Web Application Using the Apache Tomcat Manager (Windows)
  8. How to Check the Status of the Apache Tomcat Server (Linux)
  9. How to Set Default Context Path in Apache Tomcat (Windows) (this article)
  10. How to Use the autoDeploy Attribute in Apache Tomcat (Windows)
  11. How to Deploy a Web Application Using the Apache Tomcat Manager (Linux)
  12. How to List Deployed Applications Using the Apache Tomcat Manager (Windows)
  13. How to Run Multiple Instances of Apache Tomcat on One Server (Windows)
  14. How to Run a JSP Program in Apache Tomcat (Linux)
  15. How to Establish a JDBC Connection in Apache Tomcat (Windows)
  16. How to Verify Apache Tomcat Server Operation (Windows)
  17. How to Cluster in Apache Tomcat (Linux)
  18. How to Undeploy Web Applications Using the Apache Tomcat Manager (Windows)
  19. How to Set Default Context Path in Apache Tomcat (Linux)
  20. How to Use the Java Logging API in Apache Tomcat (Windows)
  21. How to Cluster in Apache Tomcat (Windows)
  22. How to Use the Java Logging API in Apache Tomcat (Linux)
  23. How to Use the autoDeploy Attribute in Apache Tomcat (Linux)
  24. How to Configure Apache Tomcat to Use MBeans (Windows)
  25. How to List Deployed Applications Using the Apache Tomcat Manager (Linux)
  26. How to Install and Configure Apache Tomcat (Windows)
  27. How to Configure Apache Tomcat to Use MBeans (Linux)