title: ServletContext getResource not working
body: <p>I'm trying to use <code>ServletContext.getResource</code> to retrieve a <code>java.net.url</code> reference to an image file (which I will then include in a PDF library using iText).<br>
  When I use <code>ServletContext.getRealPath("picture.jpg")</code>, I get back a string URL. However, getResource always returns <code>null</code>.</p>
  
  <p><strong>Example 1</strong>:</p>
  
  <pre><code>String picture = ServletContext.getRealPath("picture.jpg");
  // picture contains a non-null String with the correct path
  URL pictureURL = ServletContext.getResource(picture);
  // pictureURL is always null
  </code></pre>
  
  <p><strong>Example 2</strong>:</p>
  
  <pre><code>URL pictureURL = ServletContext.getResource("picture.jpg");
  // pictureURL is always null
  </code></pre>
  
  <p>So what is the correct way to build a java.net.URL object pointing to a file in my <code>webapps/</code> folder? Why does <code>getRealPath</code> work but not <code>getResource</code>?</p>
  
  <p>In case it helps at all, here is my folder structure</p>
  
  <pre><code>webapps -&gt; mySite -&gt; picture.jpg
  </code></pre>
  
  <p>Does my picture need to be stored in either <code>WEB-INF</code> or <code>WEB-INF/classes</code> to be read by <code>getResource</code>?</p>