title: Link to css file from Velocity template
body: <p>I am new to servlets and Velocity templates and I am trying to link my .vm template to a .css file. The .vm file and the css file are in the ROOT directory of Tomcat. The file itself displays fine but the css does not work.</p>
  
  <p>The following link does not work:</p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" href="style.css"/&gt;
  </code></pre>
  
  <p>nor does passing the filename as an attribute:</p>
  
  <pre><code>String stylesheet = "style.css";
  req.setAttribute("stylesheet", stylesheet);
  </code></pre>
  
  <p>and then referencing as such:</p>
  
  <pre><code>&lt;link rel="stylesheet" type="text/css" href="$stylesheet"/&gt;
  </code></pre>
  
  <p>Also, I cannot bring up the css file in the browser, even though it is definitely there. </p>
  
  <p>web.xml contains the following:</p>
  
  <pre><code>&lt;!-- register servlet --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;testvmservlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;net.myapp.app.TestVMServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;testvmservlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/velocity.service&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;!-- mapping all .vm files to velocity servlets --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;velocity&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.apache.velocity.tools.view.servlet.VelocityViewServlet&lt;/servlet-class&gt;
  
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;velocity&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.vm&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>Do I need to reference the css file relative to the app or relative to Velocity?</p>
  
  <p>I have since adjusted one of my servlet mappings from:</p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;startupservlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;startupservlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/foo&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>and now the css works fine. But I am unsure as to why this mapping was having an effect at all. </p>
  
  <p>As I understand it <code>&lt;url-pattern&gt;/&lt;/url-pattern&gt;</code> only applies where no path has been specified, however, a request for <code>style.css</code> should constitute a path?</p>