关于HiddenHttpMethodFilter
这个类的代码比较少,所以把整个类的代码都复制过来。在注释中添加上自己的理解。
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的更多相关文章
- Spring MVC 使用HiddenHttpMethodFilter配置Rest风格的URL
/** Rest 风格的 URL. 以 CRUD 为例: 新增: /order POST 修改: /order/1 PUT update?id=1 获取:/order/1 GET get?id=1 删 ...
- Spring3.0之后->Spring MVC过滤器-HiddenHttpMethodFilter
浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...
- springmvc的POST 请求转为 DELETE 或 put 请求配置HiddenHttpMethodFilter
1.web.xml里配置 <!-- 配置 org.springframework.web.filter.HiddenHttpMethodFilter: 可以把 POST 请求转为 DELETE ...
- SpringMVC(四):@RequestMapping结合org.springframework.web.filter.HiddenHttpMethodFilter实现REST请求
1)REST具体表现: --- /account/1 HTTP GET 获取id=1的account --- /account/1 HTTP DELETE 删除id=1的account ...
- SpringMVC(八) RequestMapping HiddenHttpMethodFilter
SpringMVC隐藏方法: 使用PUT和DELETE方法.默认HTML支持GET和POST方法.通过HiddenHttpMethodFilter将POST转成PUT和DELETE方法. 1.将Hid ...
- Spring MVC 使用拦截器 HiddenHttpMethodFilter配置Rest风格的URL
<!-- 4.使用Rest风格的URI,将页面普通的post请求转为指定的delete或者put请求 --> 详细使用请参考这篇博客:地址:http://blog.csdn.net/ppl ...
- Spring MVC添加支持Http的delete、put请求!(HiddenHttpMethodFilter)
浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...
- Spring MVC过滤器-HiddenHttpMethodFilter
参考来源:http://blog.csdn.net/geloin/article/details/7444321 浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不 ...
- Spring MVC过滤器HiddenHttpMethodFilter
浏览器form表单只支持GET与POST请求,而DELETE.PUT等method并不支持,spring3.0添加了一个过滤器,可以将这些请求转换为标准的http方法,使得支持GET.POST.PUT ...
随机推荐
- Maven的目录结构和常用命令
一.Maven项目的目录结构 1.顶级目录结构 src:该目录主要存放的是项目的源代码文件. target:该目录是项目编译后产生的一个目录,主要存放的是编译后的.class文件. pom.xm ...
- postgres entityframework foreignkey
public class Model { [Key, Column("id"), DatabaseGenerated(DatabaseGeneratedOption.Identit ...
- Android 屏蔽recent task 按钮
Step 1 Add this permission to the manifest.xml file <uses-permission android:name="android.p ...
- NoSQL集锦
1. http://blog.nosqlfan.com/,有不少Redis.CouchDB.MongoDB的电子书和文章,但没有Memcached的.
- Vue指令(四)--v-model
1.v-model的使用场景 1.v-model的使用,用于表单控件的数据绑定 2.v-model与value共同使用,实现选项框的选中事件,两者相同时,选中 3.v-model 与v-bind:va ...
- 重构指南 - 为布尔方法命名(Rename boolean method)
如果一个方法中包含多个布尔类型的参数,一是方法不容易理解,二是调用时容易出错. 重构前代码 public class BankAccount { public void CreateAccount(C ...
- git的问题(error: object file .git/objects/* is empty...)的解决方案及对git版本库文件的了解
由于操作不当,导致git版本库出了大问题,如下所示: error: object file .git/objects/8b/61d0135d3195966b443f6c73fb68466264c68e ...
- IoDH 实现的单例模式
饿汉式单例类不能实现延迟加载,不管将来用不用始终占据内存:懒汉式单例类线程安全控制烦琐,而且性能受影响.有种更好的单例模式叫做Initialization Demand Holder (IoDH)的技 ...
- org.apache.ibatis.binding.BindingException
1.异常提示: org.apache.ibatis.binding.BindingException: Mapper method 'com.artup.dao.WorksDao.selectWork ...
- Docker 简单运用
Docker 帮助系统管理员和程序员在容器中开发应用程序,并且可以扩展到成千上万的节点,容器和 VM(虚拟机)的主要区别是,容器提供了基于进程的隔离,而虚拟机提供了资源的完全隔离.虚拟机可能需要一分钟 ...