private void getHttpServletRequestInfo(HttpServletRequest request){

         try {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("--------------------------reqHeadInfos---------------------------------");
Enumeration<String> reqHeadInfos = request.getHeaderNames();
while (reqHeadInfos.hasMoreElements()) {
String headName = (String) reqHeadInfos.nextElement();
String headValue = request.getHeader(headName);//根据请求头的名字获取对应的请求头的值
stringBuilder.append(headName).append(":").append(headValue).append(";");
} stringBuilder.append("\\n--------------------------parameterNames---------------------------------\\n");
Enumeration<String> parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
String parameterName = (String) parameterNames.nextElement();
String parameterValue = request.getParameter(parameterName);//根据请求头的名字获取对应的请求头的值
stringBuilder.append(parameterName).append(":").append(parameterValue).append(";");
}
stringBuilder.append("\\n--------------------------body---------------------------------\\n");
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
String body = reader.readLine();
stringBuilder.append("body:").append(body).append(";"); stringBuilder.append("\\n--------------------------Session---------------------------------\\n");
HttpSession httpSession = request.getSession();
stringBuilder.append("SessionID:").append(httpSession.getId()).append(";");
Enumeration<String> attributeNames = httpSession.getAttributeNames();
while (attributeNames.hasMoreElements()) {
String parameterName = (String) attributeNames.nextElement();
Object parameterValue = httpSession.getAttribute(parameterName);//根据请求头的名字获取对应的请求头的值
stringBuilder.append(parameterName).append(":").append(parameterValue.toString()).append(";");
}
stringBuilder.append("\\n--------------------------Cookie---------------------------------\\n");
Cookie[] cookies = request.getCookies();
if(cookies != null){
for (Cookie cookie : cookies) {
String cookieName = cookie.getName();
String cookieValue = cookie.getValue();//根据Cookie的名字获取对应的请求头的值
stringBuilder.append(cookieName).append(":").append(cookieValue).append(";");
}
} stringBuilder.append("\\n----------------------------other-------------------------------\\n");
stringBuilder.append("characterEncoding:").append(request.getCharacterEncoding()).append(";");
stringBuilder.append("getContentLength:").append(request.getContentLength()).append(";");
stringBuilder.append("getContentType:").append(request.getContentType()).append(";");
stringBuilder.append("getAuthType:").append(request.getAuthType()).append(";");
stringBuilder.append("getMethod:").append(request.getMethod()).append(";"); stringBuilder.append("isRequestedSessionIdValid:").append(request.isRequestedSessionIdValid()).append(";");
stringBuilder.append("isRequestedSessionIdFromCookie:").append(request.isRequestedSessionIdFromCookie()).append(";");
stringBuilder.append("isRequestedSessionIdFromURL:").append(request.isRequestedSessionIdFromURL()).append(";"); Log.info("getHttpServletRequestInfo",stringBuilder.toString()); } catch (Exception e) {
Log.error("getHttpServletRequestInfo", e);
}
}

java 获取 HttpServletRequest 值 demo的更多相关文章

  1. java 获取传入值的区间

    /** * 获取值的区间 * * @param num 值 */ public static Map<String, Integer> getNumSection(Integer num) ...

  2. 工作随笔——Java调用Groovy类的方法、传递参数和获取返回值

    接触Groovy也快一年了,一直在尝试怎么将Groovy引用到日常工作中来.最近在做一个功能的时候,花了点时间重新看了下Java怎么调用Groovy的方法.传递参数和获取返回值. 示例Groovy代码 ...

  3. java调用shell获取返回值

    转自:http://blog.csdn.net/tengdazhang770960436/article/details/12014839 1.shell文件return.sh echo 1 echo ...

  4. java 获取实体类对象属性值的方法

    在java中我们要获得实体类对象的属性,一般情况是将实体类中的属性私有化,然后再对外提供get()与set()方法,然后再获取实体类对象的属性的时候先把对象new出来,再用变量名.get()的方法得到 ...

  5. storm源码之巧用java反射反序列化clojure的defrecord获取属性值

    [原创]storm源码之巧用java反射反序列化clojure的defrecord获取属性值 [原创]storm源码之巧用java反射反序列化clojure的defrecord获取属性值 storm源 ...

  6. Java获取指定时间的毫秒值的方法

    有以下两种方法获取指定时间的毫秒值: 1.Calendar类 先由getInstance获取Calendar对象,然后用clear方法将时间重置为(1970.1.1 00:00:00),接下来用set ...

  7. java获取properties配置文件值

    package me.ilt.Blog.util; import java.io.File; import java.io.FileInputStream; import java.io.IOExce ...

  8. JAVA中执行JavaScript代码并获取返回值

    JAVA中执行JavaScript代码并获取返回值 场景描述 实现思路 技术要点 代码实现 测试方法 运行结果 改进空间 场景描述 今天在CSDN上偶然看到一个帖子对于一段字符串 “var p=‘xx ...

  9. 【java】java获取对象属性类型、属性名称、属性值

    java获取对象属性类型.属性名称.属性值 获取属性 修饰符:[在Field[]循环中使用] String modifier = Modifier.toString(fields[i].getModi ...

随机推荐

  1. Trie树,又称单词查找树、字典

    在百度或淘宝搜索时,每输入字符都会出现搜索建议,比如输入“北京”,搜索框下面会以北京为前缀,展示“北京爱情故事”.“北京公交”.“北京医院”等等搜索词.实现这类技术后台所采用的数据结构是什么?[中国某 ...

  2. EasyNVR H5无插件摄像机直播解决方案前端解析之:关于直播页面和视频列表页面切换的问题

    关于直播页面和视频列表页面切换 为了给用户更好的用户体验,并且更好的让用户快速简洁的了解实时的视频直播信息.一般多会分为列表展示和实时的视频直播展示. 表面上只是两个视图之间的随意切换,其实切换的两个 ...

  3. android菜鸟学习笔记14----Android控件(三) ListView的简单使用

    MVC模式: MVC的基本原理就是通过Controller连接View和Model.当View中所显示的数据发生变化时,会通知Controller,然后由Controller调用Model中的相关方法 ...

  4. C#单元测试(转)

    C#,单元测试入门(以下内容可能来自网络) 一.什么叫单元测试(unit testing)? 是指对软件中的最小可测试单元进行检查和验证.对于单元测试中单元的含义,一般来说,要根据实际情况去判定其具体 ...

  5. runsv

    runsv(8) manual page http://smarden.org/runit/runsv.8.html Name runsv - starts and monitors a servic ...

  6. 使用AXIS2作为Client訪问WebService

    使用AXIS2,能够方便的构建WebService的server端,也能够非常方便的作为Cilent,来訪问别的WebService. 以下依据工作中的经历,整理了一下,作为Cilent訪问WebSe ...

  7. Flash+XML前后按钮超酷焦点图

    在线演示 本地下载

  8. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)

    题目链接:http://codeforces.com/contest/828 A. Restaurant Tables time limit per test 1 second memory limi ...

  9. SPOJ - PHRASES Relevant Phrases of Annihilation —— 后缀数组 出现于所有字符串中两次且不重叠的最长公共子串

    题目链接:https://vjudge.net/problem/SPOJ-PHRASES PHRASES - Relevant Phrases of Annihilation no tags  You ...

  10. 国画经典之梅花PSD素材

    国画经典之梅花图片PSD素材,由huiyi8素材网提供. 地址:http://www.huiyi8.com/meihua/​