title: How specify path to .JSP file for request.getRequestDispatcher()?
body: <p>I am confused about the meaning of request.getContextPath().  My file layout is as follows:</p>
  
  <pre><code>MyServer/WebContent:
      /Resources/MyImage.jpg
      /Resources/Scripts/MyScript.js
      /WEB-INF/JSP/MyPage.jsp
  </code></pre>
  
  <p>In the <code>MyPage.jsp</code> I am able to locate the JavaScript and image by </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script src="${pageContext.request.contextPath}/Resources/Scripts/MyScript.js"&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;img src="${pageContext.request.contextPath}/Resources/MyImage.img"&gt;
  </code></pre>
  
  <p>From this I concluded that <code>${pageContext.request.contextPath}</code> dynamically resolved to the "WebContent" folder and it is my understanding that this will resolve to this folder no matter what it is named.  That is working.</p>
  
  <p>However, from all of this I concluded that back in my .java code <code>request.getContextPath()</code> would also dynamically resolve to "WebContent".  But when I try to forward from the .java code to <code>MyPage.jsp</code> using the string formed from <code>request.getContextPath()+"/WEB-INF/JSP/MyPage.jsp"</code>, the JSP cannot be found; this results in a 404 Error - "The Requested Resource (/MyServer/WEB-INF/JSP/MyPage.jsp) is not available".  If I call <code>"/WEB-INF/JSP/MyPage.jsp"</code> we launch the JSP page. Can someone explain why pre-pending <code>request.getContextPath()</code> causes this to fail and is there something else I should use to ensure that the path to the .JSP is always resolved?</p>