java获取request请求头内容
注意一下request 和 httpServletRequest的类型文章来源地址https://www.toymoban.com/news/detail-653965.html
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
while(headerNames.hasMoreElements()) {//判断是否还有下一个元素
String nextElement = headerNames.nextElement();//获取headerNames集合中的请求头
String header2 = httpServletRequest.getHeader(nextElement);//通过请求头得到请求内容
System.err.println("请求头==========key" + nextElement + "----------VALUE:" + header2);
}
}
文章来源:https://www.toymoban.com/news/detail-653965.html
到了这里,关于java获取request请求头内容的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!