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

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;
}
}

最新文章

  1. WereWolf项目 Postmortem
  2. css判断不同分辨率显示不同宽度布局实现自适应宽度
  3. oracle触发器设置uuid变量
  4. POJ 2893 M × N Puzzle(树状数组求逆序对)
  5. win8系统 host文件无法修改解决之道
  6. Oracle 基础 游标
  7. java中四种操作(dom、sax、jdom、dom4j)xml方式详解与比较
  8. Java基础知识强化59:String(字符串)和其他类型的相互转化
  9. UVA11100- The Trip, 2007
  10. 解决HTML导出Excel表数字变成科学计数法
  11. C# 使用 SmtpClient 发送邮件注意项
  12. 堆排序(heap sort)
  13. t-sql语句创建表(基础)
  14. Linux检查和收集硬件信息的常用命令总结
  15. 【liunx】Linux下的压缩和解压缩命令——jar
  16. 论文列表——text classification
  17. Asp.net mvc怎么在razor里写js代码
  18. c语言中strcpy与strlen函数对字符串最后的'\0'的处理
  19. http://www.cnblogs.com/nangong/p/db29669e2c6d72fb3d0da947280aa1ce.htm ASP.NET从零开始学习EF的增删改查
  20. VS2010 C++环境下DLL和LIB文件的生成与调试 备忘

热门文章

  1. step6: item与pipeline
  2. javascript高性能
  3. MYSQL常用函数以及分组操作
  4. git必会必知
  5. Docker镜像保存为文件及从文件导入镜像的方法
  6. Mybatis执行sql(insert、update、delete)返回值问题
  7. 深入理解jQuery插件开发总结(三)
  8. 深入理解jQuery插件开发总结(一)
  9. StringBuffer总结分析
  10. sftp java 上传