扩展
HttpServletRequestWrapper,覆盖标头getter以返回参数:
public class AddParamsToHeader extends HttpServletRequestWrapper {
public AddParamsToHeader(HttpServletRequest request) {
super(request);
}
public String getHeader(String name) {
String header = super.getHeader(name);
return (header != null) ? header : super.getParameter(name); // Note: you can't use getParameterValues() here.
}
public Enumeration getHeaderNames() {
List names = Collections.list(super.getHeaderNames());
names.addAll(Collections.list(super.getParameterNames()));
return Collections.enumeration(names);
}
}
并用它包装原始请求:
chain.doFilter(new AddParamsToHeader((HttpServletRequest) request), response);
也就是说,我个人觉得这是一个坏主意。而是直接访问参数或将参数传递给它。