title: JSP Catch Errors
body: <p>I know this has been answered here before, and it's all over google, but I can't seem to get this to work. What I would like to do is catch 400,403,404,500 etc... </p>
  
  <p>I have a controller called index...</p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
  {
  
      String page = request.getParameter("p");
  
      if(page == null || page.equalsIgnoreCase("home"))
      {
          RequestDispatcher rd = request.getRequestDispatcher("pages/index.jsp");
          rd.forward(request, response);
      }
      else
      {
          RequestDispatcher rd = request.getRequestDispatcher("pages/error.jsp");
          rd.forward(request, response);          
      }}
  
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
  {
    doGet(request, response);
  }
  </code></pre>
  
  <p>This works fine when someone enters a url like localhost:8080/app/index?p=NOT_A_PAGE but I don't know how to catch errors if someone tries to break the url with something like localhost:8080/app/notMYController?p=home or localhost:8080/app/.</p>
  
  <p>I have seen people here, and on google say something along the lines of "Add the following line to your web.xml file which is located in your WEB-INF folder:"</p>
  
  <pre><code>&lt;error-page&gt;
      &lt;error-code&gt;500&lt;/error-code&gt;
      &lt;location&gt;/pages/error.jsp&lt;/location&gt;
  &lt;/error-page&gt;
  &lt;error-page&gt;
      &lt;error-code&gt;404&lt;/error-code&gt;
      &lt;location&gt;/pages/error.jsp&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>
  
  <p>Now I tried this, and if I go to something like "localhost:8080/app/indexs" I still get the normal Apache/Tomcat/7.0.12 404 page. </p>
  
  <p>Can someone please tell me what I am doing wrong, or what I need to do to fix this.
  Thanks :)</p>