title: How to catch non exist requested URL in Java servlet?
body: <p>My objects are stored online in two different places :</p>
  
  <p>&lt;1> On my nmjava.com site, where I can put them in a directory called "Dir_My_App/Dir_ABC/"</p>
  
  <p>&lt;2> On Google App Engine datastore</p>
  
  <p>When my Java app runs it checks both places for the objects, I designed the app so that it tries to get an object from a Url, it doesn't care whether it's an object in a directory or an object returned by a servlet.</p>
  
  <pre><code>My_Object Get_Object(String Site_Url,String Object_Path)
  {
      ... get object by the name of Object_Path from the Site_Url ...
  }
  </code></pre>
  
  <p>Now the request Url for my web site nmjava.com might look like this : </p>
  
  <p><a href="http://nmjava.com/Dir_My_App/Dir_ABC/My_Obj_123" rel="nofollow noreferrer">http://nmjava.com/Dir_My_App/Dir_ABC/My_Obj_123</a>  [ In a directory ]</p>
  
  <p>Or in the case of Google App Engine servlet : </p>
  
  <p><a href="http://nm-java.appspot.com/Check_License/Dir_My_App/Dir_ABC/My_Obj_123" rel="nofollow noreferrer">http://nm-java.appspot.com/Check_License/Dir_My_App/Dir_ABC/My_Obj_123</a> [ Non exist ]</p>
  
  <p>The "Object_Path" was generated by my app automatically. It can now get the object from my site by the above method like this :</p>
  
  <p>My_Object Get_Object("<a href="http://nmjava.com" rel="nofollow noreferrer">http://nmjava.com</a>","/Dir_My_App/Dir_ABC/My_Obj_123");</p>
  
  <p>In the Google App Engine, my servlet is running and ready to serve the object, if the request comes in correctly, but since I don't want to design my app to know whether the object is in one site's directory or in other site's datastore, I need to design the servlet to catch the non exist Url, such as the one above, and be able to make a call :</p>
  
  <p>My_Object Get_Object("<a href="http://nm-java.appspot.com/Check_License" rel="nofollow noreferrer">http://nm-java.appspot.com/Check_License</a>","/Dir_My_App/Dir_ABC/My_Obj_123");</p>
  
  <p>So my question is : When a request comes into the servlet with a non exist Url, how should it catch it and analyze the url in order to respond properly, in my case it should know that :</p>
  
  <p><a href="http://nm-java.appspot.com/Check_License/Dir_My_App/Dir_ABC/My_Obj_123" rel="nofollow noreferrer">http://nm-java.appspot.com/Check_License/Dir_My_App/Dir_ABC/My_Obj_123</a></p>
  
  <p>is asking for the object "My_Obj_123" [ ignore the dirs ] and return the object from the datastore.</p>
  
  <p>Now I'm getting this :</p>
  
  <p>Error: Not Found</p>
  
  <p>The requested URL /Check_License/Dir_My_App/Dir_ABC/My_Obj_123 was not found on this server.</p>
  
  <p>Where in my servlet and how do I detect the request for this non exist Url ? </p>