title: JSP contextPath to link to page
body: <p>I got a JSP project where i am trying to create a link in my nav.jsp that points to my frontpage (index.jsp) for navigation purposes. </p>
  
  <pre><code>&lt;nav&gt;
      &lt;ul class="menu"&gt;
          &lt;li&gt;&lt;a href="${pageContext.request.contextPath}/index.jsp"&gt;&lt;span&gt;Frontpage&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>But when i run my project, navigate to the newWebsite2015.jsp. And try to use the link in the navigation menu to get back. I get the following error.</p>
  
  <blockquote>
    <p>HTTP Status 404 - /MyNewRandomBlog1.0/article/index.jsp</p>
  </blockquote>
  
  <p>But why does it look in the article folder for the index.jsp file, instead of going to the root of the web-directory and locate the index.jsp?</p>
  
  <p>in my footer.jsp file i use pageContext.request.contextPath to retrieve an image, which works fine. </p>
  
  <pre><code>&lt;img src="${pageContext.request.contextPath}/images/farOgSon-172x190px.png" alt="image1"/&gt;
  </code></pre>
  
  <p>So i dont really understand that it does not work with the anchor.</p>
  
  <p>My web.xml looks like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"&gt;
    &lt;display-name&gt;MyNewRandomBlog1.0&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/LrGLE.png" alt="Hirachy"></p>