Spring MVC过滤器-HiddenHttpMethodFilter
参考来源:http://blog.csdn.net/geloin/article/details/7444321
浏览器form表单只支持GET与POST请求,而DELETE、PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET、POST、PUT与DELETE请求,该过滤器为HiddenHttpMethodFilter。
HiddenHttpMethodFilter的父类是OncePerRequestFilter,它继承了父类的doFilterInternal方法,工作原理是将jsp页面的form表单的method属性值在doFilterInternal方法中转化为标准的Http方法,即GET,、POST、 HEAD、OPTIONS、PUT、DELETE、TRACE,然后到Controller中找到对应的方法。例如,在使用注解时我们可能会在Controller中用于@RequestMapping(value = "list", method = RequestMethod.PUT),所以如果你的表单中使用的是<form method="put">,那么这个表单会被提交到标了Method="PUT"的方法中。
需要注意的是,由于doFilterInternal方法只对method为post的表单进行过滤,所以在页面中必须如下设置:
<form action="..." method="post">
<input type="hidden" name="_method" value="put" />
......
</form>
而不是使用:
<form action="..." method="put">
......
</form>
同时,HiddenHttpMethodFilter必须作用于dispatcher前,所以在web.xml中配置HiddenHttpMethodFilter时,需参照如下代码:
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<servlet-name>spring</servlet-name>
</filter-mapping>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:dispatcher.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
同样的,作为Filter,可以在web.xml中配置HiddenHttpMethodFilter的参数,可配置的参数为methodParam,值必须为GET,、POST、 HEAD、OPTIONS、PUT、DELETE、TRACE中的一个。
Spring MVC过滤器-HiddenHttpMethodFilter的更多相关文章
- Spring3.0之后->Spring MVC过滤器-HiddenHttpMethodFilter
浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...
- Spring MVC过滤器HiddenHttpMethodFilter
浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...
- spring mvc过滤器filter
SpringMVC 过滤器Filter使用解析 1.如上所示的spring-web.jar包结构所示, Spring的web包中中提供有很多过滤器,这些过滤器位于org.springframework ...
- Spring MVC过滤器-委派过滤器代理(DelegatingFilterProxy)
org.springframework.web.filter中有一个特殊的类——DelegatingFilterProxy,该类其实并不能说是一个过滤器,它的原型是FilterToBeanProxy, ...
- Spring MVC过滤器-字符集过滤器(CharacterEncodingFilter)
spring的字符集过滤通过用于处理项目中的乱码问题,该过滤器位于org.springframework.web.filter包中,指向类CharacterEncodingFilter,Charact ...
- Spring MVC过滤器-登录过滤
以下代码是继承OncePerRequestFilter实现登录过滤的代码: package com.test.spring.filter; import java.io.IOException; im ...
- Spring MVC 使用HiddenHttpMethodFilter配置Rest风格的URL
/** Rest 风格的 URL. 以 CRUD 为例: 新增: /order POST 修改: /order/1 PUT update?id=1 获取:/order/1 GET get?id=1 删 ...
- pring MVC过滤器-HttpPutFormContentFilter
在Spring MVC过滤器-HiddenHttpMethodFilter中我们提到,jsp或者说html中的form的method值只能为post或get,我们可以通过HiddenHttpMetho ...
- Spring MVC 分离了控制器、模型对象、过滤器以及处理程序对象的角色
通过策略接口,Spring 框架是高度可配置的,而且包含多种视图技术,例如 JavaServer Pages(JSP)技术.Velocity.Tiles.iText和POI.Spring MVC 框架 ...
随机推荐
- Android 网络连接状态的监控
有些应用需要连接网络,例如更新后台服务,刷新数据等,最通常的做法是定期联网,直接使用网上资源.缓存数据或执行一个下载任务来更新数据. 但是如果终端设备没有连接网络,或者网速较慢,就没必要执行这些任务. ...
- Same Tree (二叉树DFS)
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- 二级域名相同的情况下子页面调用父页面的js方法
这两天项目遇到这种需求.项目是一个平台级系统,其中嵌入了多款应用.在平台上可以使用这些应用操作业务. 现在产品提出了个需求:即在A应用中需要调用js方法来打开B应用. 处理方法是:平台js中给出个打开 ...
- JAVA WEB接口开发简述
目录 1. JAVA WEB接口开发简述 1.1. 基本了解 1.2. 提供接口 1.3. 调用接口 1. JAVA WEB接口开发简述 1.1. 基本了解 当我们想去访问其他网站的接口时候,而又不想 ...
- swift container server 莫名stuck
openstack swift container server的进程经常莫名其妙进入 D Ds等状态 记录一下这个时候 storage.error的log 便于分析 一种情形是下面这种log Jun ...
- WebLogic(12C)——简单公布和JDBC
一,简单公布应用 1.点击"安装".開始部署应用: 2,找到要部署的项目路径: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFue ...
- IT咨询顾问:一次吐血的项目救火 java或判断优化小技巧 asp.net core Session的测试使用心得 【.NET架构】BIM软件架构02:Web管控平台后台架构 NetCore入门篇:(十一)NetCore项目读取配置文件appsettings.json 使用LINQ生成Where的SQL语句 js_jquery_创建cookie有效期问题_时区问题
IT咨询顾问:一次吐血的项目救火 年后的一个合作公司上线了一个子业务系统,对接公司内部的单点系统.我收到该公司的技术咨询:项目启动后没有规律的突然无法登录了,重新启动后,登录一断时间后又无法重新登 ...
- hdu 1258 Sum It Up (dfs+路径记录)
pid=1258">Sum It Up Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- tesnorflow Conv2DTranspose
tensorflow/python/layers/convolutional.py # Infer the dynamic output shape: out_height = utils.decon ...
- HDoj-1250-Hat's Fibonacci-大数
Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...