在javax.servlet.Filter里设置Paramter
今天碰到一个冷僻的需求,需要在Filter里增加request的parameter,类似于
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) {...req.setParameter(paramName, paramValue);chain.doFilter(req, resp);}
public class MyFilter implements Filter {public void destroy() {}public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {...FilteredRequest filteredReq = new FilteredRequest(slingReq);filteredReq.setLabel(label);filteredReq.setDestName(destName);chain.doFilter(filteredReq, resp);}public void init(FilterConfig conf) throws ServletException {}class FilteredRequest extends HttpServletRequestWrapper {private String label;private String destName;public FilteredRequest(HttpServletRequest request) {super(request);}public void setLabel(String id) {label = id;}public void setDestName(String id) {destName = id;}public String getParameter(String paramName) {if ("label".equals(paramName)) {return label;} else if ("destName".equals(paramName)) {return destName;} else {return super.getParameter(paramName);}}}}