我有一个要求,我需要解密查询字符串。我计划通过Servlet Filter和扩展HttpServletRequestWrapper来实现,如下所示。
@WebFilter(filterName = "urlDecryptionFilter", urlPatterns = {"/*"})
public class UrlDecryptionFilter implements Filter {
static class FilteredRequest extends HttpServletRequestWrapper {
public FilteredRequest(ServletRequest request) {
super((HttpServletRequest)request);
}
public String getQueryString() {
//here i put the logic to transform the existing string
return "quertStr=modified";
}
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
chain.doFilter(new FilteredRequest(request), response);
}
@Override
public void destroy() {
}
}
但这似乎不起作用。如果有人能指出正确的方向,我将不胜感激。