Servlet Filter:如何从 servletRequest 中获取所有标头?
2022-08-31 12:12:25
这是我的样子WebFilter
@WebFilter("/rest/*")
public class AuthTokenValidatorFilter implements Filter {
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
final Enumeration<String> attributeNames = servletRequest.getAttributeNames();
while (attributeNames.hasMoreElements()) {
System.out.println("{attribute} " + servletRequest.getParameter(attributeNames.nextElement()));
}
final Enumeration<String> parameterNames = servletRequest.getParameterNames();
while (parameterNames.hasMoreElements()) {
System.out.println("{parameter} " + servletRequest.getParameter(parameterNames.nextElement()));
}
filterChain.doFilter(servletRequest, servletResponse);
}
@Override
public void destroy() {
}
}
我试图在网上找到如何从请求中获取值的信息。HTTP headers
我没有找到任何东西,所以我试图枚举,但不知道任何事情,但我没有得到任何标题。servletRequest.getAttributeNames()
servletRequest.getParameterNames()
问题
如何获取来自请求的所有标头?