zoukankan      html  css  js  c++  java
  • java 获取 HttpServletRequest 值 demo

     1     private void getHttpServletRequestInfo(HttpServletRequest request){
     2 
     3         try {
     4             StringBuilder stringBuilder = new StringBuilder();
     5             stringBuilder.append("--------------------------reqHeadInfos---------------------------------");
     6             Enumeration<String> reqHeadInfos = request.getHeaderNames();
     7             while (reqHeadInfos.hasMoreElements()) {
     8                 String headName = (String) reqHeadInfos.nextElement();
     9                 String headValue = request.getHeader(headName);//根据请求头的名字获取对应的请求头的值
    10                 stringBuilder.append(headName).append(":").append(headValue).append(";");
    11             }
    12 
    13             stringBuilder.append("\n--------------------------parameterNames---------------------------------\n");
    14             Enumeration<String> parameterNames = request.getParameterNames();
    15             while (parameterNames.hasMoreElements()) {
    16                 String parameterName = (String) parameterNames.nextElement();
    17                 String parameterValue = request.getParameter(parameterName);//根据请求头的名字获取对应的请求头的值
    18                 stringBuilder.append(parameterName).append(":").append(parameterValue).append(";");
    19             }
    20             stringBuilder.append("\n--------------------------body---------------------------------\n");
    21             BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
    22             String body = reader.readLine();
    23             stringBuilder.append("body:").append(body).append(";");
    24 
    25             stringBuilder.append("\n--------------------------Session---------------------------------\n");
    26             HttpSession httpSession = request.getSession();
    27             stringBuilder.append("SessionID:").append(httpSession.getId()).append(";");
    28             Enumeration<String> attributeNames =  httpSession.getAttributeNames();
    29             while (attributeNames.hasMoreElements()) {
    30                 String parameterName = (String) attributeNames.nextElement();
    31                 Object parameterValue = httpSession.getAttribute(parameterName);//根据请求头的名字获取对应的请求头的值
    32                 stringBuilder.append(parameterName).append(":").append(parameterValue.toString()).append(";");
    33             }
    34             stringBuilder.append("\n--------------------------Cookie---------------------------------\n");
    35             Cookie[] cookies = request.getCookies();
    36             if(cookies != null){
    37                 for (Cookie cookie : cookies) {
    38                     String cookieName = cookie.getName();
    39                     String cookieValue = cookie.getValue();//根据Cookie的名字获取对应的请求头的值
    40                     stringBuilder.append(cookieName).append(":").append(cookieValue).append(";");
    41                 }
    42             }
    43 
    44             stringBuilder.append("\n----------------------------other-------------------------------\n");
    45             stringBuilder.append("characterEncoding:").append(request.getCharacterEncoding()).append(";");
    46             stringBuilder.append("getContentLength:").append(request.getContentLength()).append(";");
    47             stringBuilder.append("getContentType:").append(request.getContentType()).append(";");
    48             stringBuilder.append("getAuthType:").append(request.getAuthType()).append(";");
    49             stringBuilder.append("getMethod:").append(request.getMethod()).append(";");
    50 
    51             stringBuilder.append("isRequestedSessionIdValid:").append(request.isRequestedSessionIdValid()).append(";");
    52             stringBuilder.append("isRequestedSessionIdFromCookie:").append(request.isRequestedSessionIdFromCookie()).append(";");
    53             stringBuilder.append("isRequestedSessionIdFromURL:").append(request.isRequestedSessionIdFromURL()).append(";");
    54 
    55             Log.info("getHttpServletRequestInfo",stringBuilder.toString());
    56 
    57         } catch (Exception e) {
    58             Log.error("getHttpServletRequestInfo", e);
    59         }
    60     }
  • 相关阅读:
    优化前台标题,导航,面包屑导航,列表页左侧产品属性,及分类h1标签内文字。
    php Undefined index和Undefined variable的解决方法$_GET
    1 一段很简洁很棒的原生态javascript的Ajax代码
    navicat for mysql 快捷键
    magento 1.6.1.0 安装不上,提示报错:There has been an error processing your request
    libmcrypt.dll
    日志分析软件
    magento本地安装成功后无法进入后台,密码和用户名均正确 .
    禁止所有搜索引擎访问网站的任何部分
    magento安装心得
  • 原文地址:https://www.cnblogs.com/baoconghui/p/7359014.html
Copyright © 2011-2022 走看看