java后台文件上传 commons-fileupload

        在Spring MVC过滤器-HiddenHttpMethodFilter中 我们提到,jsp或者说html中的form的method值只能为post或get,我们可以通过HiddenHttpMethodFilter获取 put表单中的参数-值,而在Spring3.0中获取put表单的参数-值还有另一种方法,即使用HttpPutFormContentFilter过 滤器。

        HttpPutFormContentFilter过滤器的作为就是获取put表单的值,并将之传递到Controller中标注了method为RequestMethod.put的方法中。

        在web.xml中配置HttpPutFormContentFilter的代码类似如下:

[java] view plaincopy

  1. <filter>  

  2.     <filter-name>httpPutFormcontentFilter</filter-name>  

  3.     <filter-class>org.springframework.web.filter.HttpPutFormContentFilter</filter-class>  

  4. </filter>  

  5. <filter-mapping>  

  6.     <filter-name>httpPutFormContentFilter</filter-name>  

  7.     <url-pattern>/*</url-pattern>  

  8. </filter-mapping>  

        需要注意的是,该过滤器只能接受enctype值为application/x-www-form-urlencoded的表单,也就是说,在使用该过滤器时,form表单的代码必须如下:

[java] view plaincopy

  1. <form action="" method="put" enctype="application/x-www-form-urlencoded">  

  2. ......  

  3. </form> 


你可能感兴趣的:(java后台文件上传 commons-fileupload)