4 Replies Latest reply: Oct 14, 2011 3:10 AM by gimbal2 RSS

    Configuring context root

    802569
      This question is more related to Tomcat environment setup, but I figure that someone here will know the answer. I have five webapps on my tomcat server. For each, I would like to set a context root, so that when I reference a resource (css, js, etc) from a web page in one of these apps, I can reference it through a relative root path without having to put the webapp name in the path. For example, as it is now, I need to write
      <link rel="stylesheet" type="text/css" href="/MyWebApp/css/styles.css" />
      I want to set the root so that I can instead reference like
      <link rel="stylesheet" type="text/css" href="/css/styles.css" />
      I remember doing something similar many years back, but cannot find a solution - if there even is one.
        • 1. Re: Configuring context root
          DrClap
          Nothing to do with Tomcat environment setup. Here's an example which produces a link based on the context name of the web application:
          <link rel="icon" href="${pageContext.request.contextPath}/images/favicon.ico"/>
          • 2. Re: Configuring context root
            802569
            Is there not a way to set that location though somewhere in a tomcat config file? I vaguely remember doing it in the context.xml file, but everything ive tried doesn't seem to work.
            • 3. Re: Configuring context root
              DrClap
              I expect there's a way to configure it. But that doesn't excuse you from having to put the context name in your URL, no matter where you declare it. Which perhaps is why nothing "works" for you.
              • 4. Re: Configuring context root
                gimbal2
                799566 wrote:
                Is there not a way to set that location though somewhere in a tomcat config file? I vaguely remember doing it in the context.xml file, but everything ive tried doesn't seem to work.
                Yes, you can define a META-INF/context.xml file and override the context path that way. It will be something like:
                <Context path="/yourapp">
                <!-- other config here -->
                </Context>
                But as said, that won't help you.