Forum Stats

  • 3,816,099 Users
  • 2,259,141 Discussions
  • 7,893,390 Comments

Discussions

Configuring context root

802569
802569 Member Posts: 29
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.

Answers

  • DrClap
    DrClap Member Posts: 25,479
    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"/>
  • 802569
    802569 Member Posts: 29
    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.
  • DrClap
    DrClap Member Posts: 25,479
    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.
  • gimbal2
    gimbal2 Member Posts: 11,949 Gold Trophy
    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.
This discussion has been closed.