• 关于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;
            }
        }
  • 相关阅读:
    Nginx专题(二)-----虚拟主机、location规则、rewrite、负载均衡配置
    Nginx专题(一)-----简介
    springMVC自动转义问题
    Tomcat专题(三)-----Tomcat性能优化
    Tomcat专题(二)-----Tomcat源码、嵌入式Tomcat
    Tomcat专题(一)-----架构体系
    jvm性能调优(五)-----深入了解性能优化
    jvm性能调优(四)-----编写高效的java代码
    jvm性能调优(三)-----JVM的执行子系统
    jvm性能调优(二)-----垃圾回收、内存分配
  • 原文地址:https://www.cnblogs.com/GooPolaris/p/7919666.html
Copyright © 2020-2023  润新知