title: Website works locally, but when deployed on Tomcat server it no longer finds Servlets
body: <h1>Background</h1>
  
  <p><hr>
  I'm working on a project for school. The goal is to create a learning website in the end. I've been creating my website locally and testing it going great so far, so I dediced to place it on the server to test it out there (deploy .war file). And as soon as I did that the whole website seems to not work.<br>
  <br></p>
  
  <h1>Problem</h1>
  
  <p><hr>
  The problem is that as soon as I try to click on any of my links that go through servlets, I get an error from tomcat saying that the requested resource is not available (http status 404). Which is sort of weird because it does work locally.<br>
  <br></p>
  
  <h1>What have I tried</h1>
  
  <p><hr>
  The first thing I noticed was that going to the server .war file is going to a snapshot url first (in my case: <code>http://145.92.6.85:8080/PDL-1.0-SNAPSHOT/</code>) instead of just landing on the index.jsp page right away (which happens locally) so my first thought was that it was using a whole different way to access the files I was looking for. Again strange because locally everything is working fine (using tomcat as well). I looked inside my project and tried to access the files I was looking for using the map structure, and this seemed to work. So instead of using the servlet I specified on the web.xml it's just ignoring it.<br>
  <br>
  So then I decided it probaply can't find my web.xml file. I did a little searching online and found that it should be placed inside the map WEB-INF. Currently web.xml was sitting in META-INF, so placed it in WEB-INF, but to no avail. The pages I'm looking for still can't be found. I also read that some people said the classes for the projects (which I assume to be my servlets?) need to be placed inside a <code>classes</code> directory inside the WEB-INF folder. I decided not to do this, because currently I've got them all set up in different packages (Source Packages -> controllers/models etc.). And that seemed a lot more logical to me, and besides it's working locally so why would this not work on the server?</p>
  
  <p>As far as I can tell my web.xml is set up correctly, but I'll show some code to indicate what the problem is.<br>
  <br></p>
  
  <h1>Code</h1>
  
  <p><hr>
  This is the URL I'm trying to follow (inside a navigation bar) (follows: <code>http://145.92.6.85:8080/PDL/inlog</code>)</p>
  
  <pre><code>&lt;li&gt;
      &lt;a href="/PDL/inlog"&gt;Log In&lt;/a&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>this is the web.xml</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;login&lt;/servlet-name&gt;
      &lt;servlet-class&gt;controllers.login&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;login&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/login&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>The inlog.java file (inside Source Packages->controllers or PDL/src/main/java/controllers)</p>
  
  <pre><code>@Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      RequestDispatcher rd = request.getRequestDispatcher("/pages/inlog.jsp");
      rd.forward(request, response);
  }
  </code></pre>
  
  <p>This is where it breaks because it could not be found.</p>
  
  <p><br></p>
  
  <h1>Finally</h1>
  
  <p><hr>
  Whilst writing this question I do feel as if my URL's and stuff are maybe a little bit too changing and perhaps should be more dynamic than the current static ones (since the server enviroment is different I guess). Could anyone give me some tips as how to make the urls more dynamic, so they would work locally and on the server straight away (something like the PHP equivalent of <code>$_SERVER['SERVER_NAME']</code> and the like? Any help would be greatly appreciated! Though I feel that the urls im redirecting to are the problem I just don't know how to solve this.</p>