title: Spring upload file problems
body: <p>I need to upload file from browser to server. I use spring 3.2 as my web framework.</p>
  
  <p>So i configured my app like this.</p>
  
  <p>1 -  I got web.xml </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextClass&lt;/param-name&gt;
          &lt;param-value&gt;org.springframework.web.context.support.AnnotationConfigWebApplicationContext&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;racoonsoft.chaos.settings&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;admin/library&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>2 - MainConfig class</p>
  
  <pre><code>@Configuration
  @Import({WebConfig.class })
  public class MainConfig {
      @Bean
      public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
          return new PropertySourcesPlaceholderConfigurer();
      }
  
      @Bean
      public static ScheduledAnnotationBeanPostProcessor scheduledAnnotationBeanPostProcessor() {
          return new ScheduledAnnotationBeanPostProcessor();
      }
  
      @Bean
      public static StandardServletMultipartResolver multipartResolver() {
          StandardServletMultipartResolver resolver = new StandardServletMultipartResolver();
          return resolver;
      }
  }
  </code></pre>
  
  <p>3 - Controller to handle multipart uploads</p>
  
  <pre><code>@Controller
  @MultipartConfig(fileSizeThreshold=1024*1024*2, // 2MB
          maxFileSize=1024*1024*10,      // 10MB
          maxRequestSize=1024*1024*50)
  public class FileUpload
  {
      public static final int UPLOAD_RESULT_OK = 100000;
      @Autowired
      BookDao book_dao;
  
      @RequestMapping(value = "/admin/library/upload_file", method = RequestMethod.POST)
      public String saveFiles(@RequestParam("file-file") MultipartFile file) throws IOException
      {
          if (!file.isEmpty())
          {
              byte[] bytes = file.getBytes();
              return "redirect:caps/total_fail";
          }
          else
          {
              return "redirect:caps/total_fail";
          }
      }
  }
  </code></pre>
  
  <p>4 - jsp  where i placed my form to submit files </p>
  
  <pre><code>...&lt;form method="post" action="/admin/library/upload_file" enctype="multipart/form-data"&gt;
                  &lt;input type="text" name="name"/&gt;
                  &lt;input type="file" name="file-file"/&gt;
                  &lt;input type="submit"/&gt;
              &lt;/form&gt;...
  </code></pre>
  
  <p>When i submit my form i got an Exception </p>
  
  <pre><code>org.springframework.web.bind.MissingServletRequestParameterException: Required MultipartFile parameter 'file-file' is not present
      org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.handleMissingValue(RequestParamMethodArgumentResolver.java:202)
  </code></pre>
  
  <p>I got no idea why. When i remove @RequestParam annotaion i got my method invoked but file parameter = null. 
  What is my problem?</p>