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. Memcache安装与使用

    一.资源下载 安装memcached 之前必需要先安装 libevent 分别在libevent和memcached的官网下载安装包libevent-1.4.14b-stable.tar.gz和mem ...

  2. 关于dubbo的负载均衡

    1 dubbo的集群 将同一个服务部署到多个机器上,然后全部注册到注册中心.这样的多个机器就是一个dubbo集群了. 2 dubbo的负载均衡是怎么回事 由于多台机器上都有同一个服务,因此consum ...

  3. Kafka核心思想

    Kafka是2010年12月份开源的项目,采用Scala语言编写,使用了多种效率优化机制,整体架构比较新颖(push/pull),更适合异构集群. 设计目标: (1) 数据在磁盘上的存取代价为O(1) ...

  4. js添加方法和邦定事件

    function(obj,objArr){ if(($(obj).attr("type") == "checkbox" && $j(obj).p ...

  5. JS dom最常用API

    //document方法:    var cont = document.getElementByIdx_x('cont'); //className给标签添加class    cont.classN ...

  6. ThreadLocalMap里Entry声明为WeakReference

    Java里,每个线程都有自己的ThreadLocalMap,里边存着自己私有的对象.Map的Entry里,key为ThreadLocal对象,value即为私有对象T.在spring MVC中,常用T ...

  7. Docker实践中遇到的坑

    1.docker容器中后台运行退出执行curl+p+q,再次进入执行命令docker attach 容器id. 2.容器中exit退出后,还原方法为docker ps -a 查看历史运行容器,dock ...

  8. 爬虫之重要的requests模块

    一 . requests模块 什么是requests模块 requests模块是python中原生的基于网络请求的模块,其主要作用是用来模拟浏览器发起请求.功能强大,用法简洁高效.在爬虫领域中占据着半 ...

  9. could not read symbols: Archive has no index;

    could not read symbols: Archive has no index; run ranlib to add one collect2: ld returned 1 exit sta ...

  10. HAOI 2017 游记

    省选 2017年4月23日 流水账式游记,不喜勿喷. Day0: 准备出发,上午敲了一顿板子,板子敲完了就打小游戏,老师也不管了. 过程中各种奶,说什么今年一定考仙人掌啦,今年一定考字符串啦,今年一定 ...