title: Getting the absolute context path of a webapp inside a Velocity template
body: <p>I have a fairly simple (I hope :P) question.</p>
  
  <p>I know that in good old Java servlet code, I can derive the full request path of a request that comes into the web server like this:</p>
  
  <pre><code>String requestBaseUrl = 
      String.format("%s://%s:%s%s", request.getScheme(), request.getServerName(), 
              request.getServerPort(), request.getContextPath());
  </code></pre>
  
  <p>Now, doing the exact same thing in JSP is pretty straightforward to do. However, I now have to do this in Velocity 1.5 template. Specifically, I need to output that information as the 'codebase' attribute of a webstart applet I need to integrate into my web application.</p>
  
  <p>I tried this, but the applet refused to start, instead throwing a FileNotFoundException :P</p>
  
  <pre><code>&lt;script src="http://www.java.com/js/deployJava.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      var attributes = { code:'org.groundhog.MyApplet', width:360, height:280} ;
      var parameters = {
          jnlp_href: './webstart/myapplet.jnlp', &lt;------------------ this
          bgColor: '#4f616d', mayscript: true
      };
      deployJava.runApplet(attributes, parameters, '1.6');
  </code></pre>
  
  <p>So I think that the most reliable way to do this is to derive and stick in the absolute URL where the application is running, and reference the applet's jnlp file from there using the same logic as in my previous Java snippet.</p>
  
  <p>Right now I'm shuffling through Velocity's documentation. But, if anyone has had to deal with something similar, I'd be thankful for the equivalent idiom in Velocity.</p>
  
  <p>I thank you for your time and help!</p>