这个类的代码比较少,所以把整个类的代码都复制过来。在注释中添加上自己的理解。

public class HiddenHttpMethodFilter extends OncePerRequestFilter {

    /** Default method parameter: {@code _method} */
public static final String DEFAULT_METHOD_PARAM = "_method"; private String methodParam = DEFAULT_METHOD_PARAM; /**
* Set the parameter name to look for HTTP methods.
* @see #DEFAULT_METHOD_PARAM
*/
public void setMethodParam(String methodParam) {
Assert.hasText(methodParam, "'methodParam' must not be empty");
this.methodParam = methodParam;
} @Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException { HttpServletRequest requestToUse = request;
//如果这是一个POST请求
if ("POST".equals(request.getMethod()) && request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) == null) {
//接着获取参数值比如:PUT、DELETE等
String paramValue = request.getParameter(this.methodParam);
//封装成的相应的请求
if (StringUtils.hasLength(paramValue)) {
requestToUse = new HttpMethodRequestWrapper(request, paramValue);
}
}
//最后将请求发送给下一个filter
filterChain.doFilter(requestToUse, response);
} /**
* Simple {@link HttpServletRequest} wrapper that returns the supplied method for
* {@link HttpServletRequest#getMethod()}.
*/
private static class HttpMethodRequestWrapper extends HttpServletRequestWrapper { private final String method;
    
public HttpMethodRequestWrapper(HttpServletRequest request, String method) {
super(request);
this.method = method.toUpperCase(Locale.ENGLISH);
} @Override
public String getMethod() {
return this.method;
}
}

关于HiddenHttpMethodFilter的更多相关文章

  1. Spring MVC 使用HiddenHttpMethodFilter配置Rest风格的URL

    /** Rest 风格的 URL. 以 CRUD 为例: 新增: /order POST 修改: /order/1 PUT update?id=1 获取:/order/1 GET get?id=1 删 ...

  2. Spring3.0之后->Spring MVC过滤器-HiddenHttpMethodFilter

    浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...

  3. springmvc的POST 请求转为 DELETE 或 put 请求配置HiddenHttpMethodFilter

    1.web.xml里配置 <!-- 配置 org.springframework.web.filter.HiddenHttpMethodFilter: 可以把 POST 请求转为 DELETE ...

  4. SpringMVC(四):@RequestMapping结合org.springframework.web.filter.HiddenHttpMethodFilter实现REST请求

    1)REST具体表现: --- /account/1  HTTP GET       获取id=1的account --- /account/1  HTTP DELETE 删除id=1的account ...

  5. SpringMVC(八) RequestMapping HiddenHttpMethodFilter

    SpringMVC隐藏方法: 使用PUT和DELETE方法.默认HTML支持GET和POST方法.通过HiddenHttpMethodFilter将POST转成PUT和DELETE方法. 1.将Hid ...

  6. Spring MVC 使用拦截器 HiddenHttpMethodFilter配置Rest风格的URL

    <!-- 4.使用Rest风格的URI,将页面普通的post请求转为指定的delete或者put请求 --> 详细使用请参考这篇博客:地址:http://blog.csdn.net/ppl ...

  7. Spring MVC添加支持Http的delete、put请求!(HiddenHttpMethodFilter)

    浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...

  8. Spring MVC过滤器-HiddenHttpMethodFilter

    参考来源:http://blog.csdn.net/geloin/article/details/7444321 浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不 ...

  9. Spring MVC过滤器HiddenHttpMethodFilter

    浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...

随机推荐

  1. Db - DataAccess

    /* Jonney Create 2013-8-12 */ /*using System.Data.OracleClient;*/ /*using System.Data.SQLite;*/ /*us ...

  2. 三年从前端小工到架构-知乎 Live 学习整理

    最近在知乎上学习了vczero (王利华,簋谣)的知乎Live「三年从前端小工到架构」,感觉受益匪浅,现将本次Live学习笔记记录如下. 本次 Live 主要包括以下内容   • 0-3 年的前端工程 ...

  3. 2017年12月16日 ASP.NET基本用法

    ASP.NET初级添加 利用css代码跟ASP.NET还有Javascript原生,LinQ来写增跟展示数据 首先介绍一个非常好用的控件,灵活并且循环展示数据库里面的数据 <asp:Repeat ...

  4. 实例化geoserver wms服务

    var vectorWmsJHdataLayer = new ol.layer.Tile({ source: new ol.source.TileWMS({ //地址 url:'http://loca ...

  5. Rabbit的事务

    加入事务的方法: txSelect()  txCommit()  txRollback() 生产者: package com.kf.queueDemo.transactions; import jav ...

  6. Rabbit主题交换机

    主题交换机类型为:topic. 是直连交换机的一种.只是比直连交换机更灵活,在路由键上引入了通配符的概念 topic交换机支持通配符的路由键. *表示匹配一个词. #匹配所有 生产者 : packag ...

  7. Java基础(四)方法和数组

    一.方法 1.方法的定义 方法也叫函数,就是一个能独立完成某个功能的一段代码.方法可以看作一个整体. 语法: 修饰符 返回类型 方法名字(数据类型 变量名,数据类型 变量名,……[形式参数(0个到n个 ...

  8. DataTables固定表格宽度(设置横向滚动条)

    当表格的列比较多的时候,可能就需要固定表格的宽度了,默认的100%宽已经不适应了.默认的100%宽要实现改变窗口大小也100%的话,在table元素上添加width="100%", ...

  9. MyBatis_动态代理

    一.项目结构 二.代码实现 import java.util.List; import java.util.Map; import com.jmu.bean.Student; public inter ...

  10. ccf-201609-3 炉石传说

    问题描述 <炉石传说:魔兽英雄传>(Hearthstone: Heroes of Warcraft,简称炉石传说)是暴雪娱乐开发的一款集换式卡牌游戏(如下图所示).游戏在一个战斗棋盘上进行 ...