title: Catch Spring MVC Maxupload Size Error
body: <p>I know its hard to check the file size at the client side(browser) with just pure javascript only.</p>
  
  <p>Now, my question is, Is there a way at the server side to catch an exception such as this?</p>
  
  <pre><code>org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size of 2000000 bytes
  </code></pre>
  
  <p>What happens is that, it does not reach my @controller post method and it just throws up the exception that is being catch up by my error.jsp.</p>
  
  <p>What I was thinking is that, is it possible to do this in spring mvc annotated method?</p>
  
  <pre><code>@RequestMapping("/uploadFile.htm")
      public String uploadAttachment(
          HttpServletRequest request,
          @RequestParam(required = false, value = "attached-file") MultipartFile file,
          ModelMap model) throws Exception {
  
          if(checkfilesize(file)){
              //populate model
              //add error if appplicable
              //return same form again
          }
          //return success
      }       
  }
  </code></pre>
  
  <p>My problem is, it doesnt reaches upto this point and just throw up a big fat exception.</p>
  
  <p>Although the error.jsp was able to catch it, I would think its much user friendly if I can
  alert the user that the file they are about to upload exceeds the limit.</p>
  
  <p>This is Spring MVC 2.5 app by the way.  Is this possible?</p>