title: Servlet mapping: url pattern problems
body: <p>I'm trying to set up a servlet mapping so that urls in the form "/getFile/{fileId}" will be mapped by my DispatcherServlet "dispatcher".</p>
  
  <p>If I set up my web.xml as below only "/getFile" will be mapped, I can't append the fileId or it breaks.</p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/getFile&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>So I would have thought that I should use </p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/getFile/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>But this doesn't work at all.</p>
  
  <p>The method I'm trying to call is</p>
  
  <pre><code>  @RequestMapping(value = "/getFile/{documentId}", method = RequestMethod.GET)
  public void getFile(@PathVariable int documentId, HttpServletResponse response) throws Exception {
      User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  
      UserDB userDB = UserDBService.getUser(user.getUsername());
  
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      Document document = DocumentService.getDocument(documentId);
      String extension = document.getExtension();
      try {
          String path = ApplicationPropertiesConstants.SAFESITE_DOCUMENTS_DIRECTORY + userDB.getSite().getId() + "\\" + documentId + "." + extension;
          InputStream is = new FileInputStream(path);
  
          response.setHeader("Cache-Control", "no-store");
          response.setHeader("Pragma", "no-cache");
          response.setDateHeader("Expires", 0);
          response.setContentType("image/png");
          org.apache.commons.io.IOUtils.copy(is, response.getOutputStream());
  
          response.flushBuffer();
      } catch (IllegalArgumentException e) {
          response.sendError(HttpServletResponse.SC_NOT_FOUND);
      }
  
  }
  </code></pre>
  
  <p>Any idea what I'm doing wrong?</p>
  
  <p>Edit: it's not a duplicate as below because I do not have a servlet mapping of just "/". Thus there is no default fall back mapping.</p>
  
  <p>My full mapping.</p>
  
  <pre><code> &lt;servlet&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;rest&lt;/servlet-name&gt;            
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/getFile/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;rest&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.json&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>