核心原理就是一个类:javax.servlet.http.HttpServletRequestWrapper
一个简单的例子,当任何请求的参数里有 aaa的时候,把它的值改成 bbb
新增一个类自定义的类 CustomHttpServletRequestWrapper
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; public class CustomHttpServletRequestWrapper extends HttpServletRequestWrapper { public CustomHttpServletRequestWrapper(HttpServletRequest request) { super(request); } @Override public String getParameter(String name) { if ("aaa".equals(name)) { return "bbb"; } return super.getParameter(name); } }
然后在Filter过滤器里使用这个类
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { CustomHttpServletRequestWrapper xssRequest = new CustomHttpServletRequestWrapper((HttpServletRequest) request); filterChain.doFilter(xssRequest, response); }
标签:HttpServletRequest,JavaWeb,YhtHttpServletRequestWrapper,request,javax,CustomHttp From: https://www.cnblogs.com/acm-bingzi/p/post_param.html