jsp页面头信息遍历

时间:2022-02-24 19:38:45
  1. //打印header  
  2. @SuppressWarnings("rawtypes")  
  3.     private void printHeader(HttpServletRequest request) {  
  4.         Enumeration names = request.getHeaderNames();  
  5.         StringBuilder sb = new StringBuilder("headerInfo---");  
  6.         while(names.hasMoreElements()) {  
  7.             String name = names.nextElement().toString();  
  8.             Enumeration headers = request.getHeaders(name);  
  9.             sb.append(name).append(":");  
  10.             while(headers.hasMoreElements()) {  
  11.                 sb.append(headers.nextElement()).append(" ");  
  12.             }  
  13.             sb.append("\n");  
  14.         }  
  15.         System.out.println(sb.toString());  
  16.     }  
  17.       
  18.       

Java代码   jsp页面头信息遍历
  1. //打印request  
  2. private void printRequest(HttpServletRequest request) {  
  3.         StringBuilder sb = new StringBuilder("request----");  
  4.         sb.append("servletPath:").append(request.getServletPath()).append(" ");  
  5.         sb.append("servletPort:").append(request.getServerPort()).append(" ");  
  6.         sb.append("serverName:").append(request.getServerName()).append(" ");  
  7.         sb.append("scheme:").append(request.getScheme()).append(" ");  
  8.         sb.append("requestUrl:").append(request.getRequestURL().toString()).append("\n");  
  9.         sb.append("requestUri:").append(request.getRequestURI()).append(" ");  
  10.         sb.append("RequestedSessionId:").append(request.getRequestedSessionId()).append(" ");  
  11.         sb.append("remoteUser:").append(request.getRemoteUser()).append(" ");  
  12.         sb.append("authType:").append(request.getAuthType()).append(" ");  
  13.         sb.append("characterEncoding:").append(request.getCharacterEncoding()).append(" ");  
  14.         sb.append("contentLength:").append(request.getContentLength()).append(" ");  
  15.         sb.append("contentType:").append(request.getContentType()).append(" ");  
  16.         sb.append("contextPath:").append(request.getContextPath()).append(" ");  
  17.         sb.append("localAddr:").append(request.getLocalAddr()).append("\n");  
  18.         sb.append("localName:").append(request.getLocalName()).append(" ");  
  19.         sb.append("method:").append(request.getMethod()).append(" ");  
  20.         sb.append("pathInfo:").append(request.getPathInfo()).append(" ");  
  21.         sb.append("pathTranslated:").append(request.getPathTranslated()).append(" ");  
  22.         sb.append("protocol:").append(request.getProtocol()).append(" ");  
  23.         sb.append("queryString:").append(request.getQueryString()).append(" ");  
  24.         sb.append("remoteAddr:").append(request.getRemoteAddr()).append(" ");  
  25.         sb.append("remotePort:").append(request.getRemotePort()).append(" ");  
  26.         System.out.println(sb.toString());  
  27.     }