zoukankan      html  css  js  c++  java
  • 关于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;
            }
        }
  • 相关阅读:
    Pandas 合并,连接,连接和比较
    根据条件在Pandas DataFrame中选择行
    pandas DataFrame.where() 检查一个或多个条件的数据帧,并相应地返回结果
    获取包含给定子字符串的Pandas DataFrame中的所有行
    Pandas Series.str.contains
    Python | 查找给定字符串中字符的位置
    Python中的Enumerate()
    Python –遍历NumPy中的列
    Boost 编译
    opencv 提取RGB并用cocos2d-x 纹理方式显示
  • 原文地址:https://www.cnblogs.com/GooPolaris/p/7919666.html
Copyright © 2011-2022 走看看