Spring MVC过滤器-HttpPutFormContentFilter

本文介绍 Spring MVC 中 HttpPutFormContentFilter 的配置与使用方法,此过滤器用于处理 PUT 请求中的表单数据,并需搭配正确的 enctype 设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 plain  copy
  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 plain  copy
  1. <form action="" method="put" enctype="application/x-www-form-urlencoded">  
  2. ......  
  3. </form>  

资料来源:http://blog.youkuaiyun.com/geloin/article/details/7444590


让我们一起遨游在代码的海洋里!


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值