在请求中给header添加参数

 

在过滤器或拦截器中如何给放行的header添加参数,  参考如下方式: 需要定义一个类来集成HttpServletRequestWrapper , 增加方法实现

public final class MutableHttpServletRequest extends HttpServletRequestWrapper {

    private final Map<String, String> customHeaders;

    /**
     * @param request
     */
    public MutableHttpServletRequest(HttpServletRequest request) {
        super(request);
        this.customHeaders = new HashMap<String, String>();
    }

    public void putHeader(String name, String value) {
        this.customHeaders.put(name, value);
    }

}

 

在过滤器中:

@Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {

                request.setAttribute("uid", uid);

                HttpServletRequest req = (HttpServletRequest) request;
                MutableHttpServletRequest mutableRequest = new MutableHttpServletRequest(req);
                mutableRequest.putHeader("uid", uid);
                filterChain.doFilter(request, response);
            }
        }
    }

 

不会,我可以学;落后,我可以追赶;跌倒,我可以站起来;我一定行!

上一篇:HTML5增强网络安全 同时带来新安全漏洞


下一篇:强大的HTML5幻灯片系统:H5Slides