java 获取 HttpServletRequest 值 demo
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的更多相关文章
- java 获取传入值的区间
/** * 获取值的区间 * * @param num 值 */ public static Map<String, Integer> getNumSection(Integer num) ...
- 工作随笔——Java调用Groovy类的方法、传递参数和获取返回值
接触Groovy也快一年了,一直在尝试怎么将Groovy引用到日常工作中来.最近在做一个功能的时候,花了点时间重新看了下Java怎么调用Groovy的方法.传递参数和获取返回值. 示例Groovy代码 ...
- java调用shell获取返回值
转自:http://blog.csdn.net/tengdazhang770960436/article/details/12014839 1.shell文件return.sh echo 1 echo ...
- java 获取实体类对象属性值的方法
在java中我们要获得实体类对象的属性,一般情况是将实体类中的属性私有化,然后再对外提供get()与set()方法,然后再获取实体类对象的属性的时候先把对象new出来,再用变量名.get()的方法得到 ...
- storm源码之巧用java反射反序列化clojure的defrecord获取属性值
[原创]storm源码之巧用java反射反序列化clojure的defrecord获取属性值 [原创]storm源码之巧用java反射反序列化clojure的defrecord获取属性值 storm源 ...
- Java获取指定时间的毫秒值的方法
有以下两种方法获取指定时间的毫秒值: 1.Calendar类 先由getInstance获取Calendar对象,然后用clear方法将时间重置为(1970.1.1 00:00:00),接下来用set ...
- java获取properties配置文件值
package me.ilt.Blog.util; import java.io.File; import java.io.FileInputStream; import java.io.IOExce ...
- JAVA中执行JavaScript代码并获取返回值
JAVA中执行JavaScript代码并获取返回值 场景描述 实现思路 技术要点 代码实现 测试方法 运行结果 改进空间 场景描述 今天在CSDN上偶然看到一个帖子对于一段字符串 “var p=‘xx ...
- 【java】java获取对象属性类型、属性名称、属性值
java获取对象属性类型.属性名称.属性值 获取属性 修饰符:[在Field[]循环中使用] String modifier = Modifier.toString(fields[i].getModi ...
随机推荐
- 嵌入式开发之davinci--- 8148/8168/8127 中的xdc 简介
XDC是TI公司为嵌入式实时系统可重用软件组件(在XDC里被成为packages,以下成为包)制定的一套标准.它包括一些有用的工具,标准的API函数,静态配置文件和打包(packaging)操作.XD ...
- uva 12083 Guardian of Decency (二分图匹配)
uva 12083 Guardian of Decency Description Frank N. Stein is a very conservative high-school teacher. ...
- 概率dp HDU 4405
Aeroplane chess Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- python 基础 1.5 python数据类型(三)--元组常用方法示例
#/usr/bin/python#coding=utf-8#@Time :2017/10/13 15:02#@Auther :liuzhenchuan#@File :元组.py #tuple() 字符 ...
- IOS GameCenter验证登陆
#import "GameKitHelper.h" #import "GameConstants.h" @interface GameKitHelper () ...
- LoadRunner hits per second 深入理解
Hits per Second Graph The Hits per Second graph shows the number of HTTP requests made by Vusers to ...
- python编程基础:《http://www.cnblogs.com/wiki-royzhang/category/466416.html》
windows自动化 http://www.cnblogs.com/wiki-royzhang/category/466416.html
- git config --system --unset credential.helper 重新输入账号密码
检查本地配置$ git config --local -lcore.repositoryformatversion=0core.filemode=falsecore.bare=falsecore.lo ...
- var foo = "11"+2+"1"; console.log(foo); //1121 好多文章答案写错了,我发下给初学的朋友看到,以免一开始就学错了
体会加一个字符串'1' 和 减去一个字符串'1'的不同 var foo = "11"+2-"1"; console.log(foo); //111 consol ...
- Java基础教程:面向对象编程[1]
Java基础教程:面向对象编程 内容大纲 Java语言概述 Java语言特点 1.Java为纯面向对象的语言,它能够直接反映现实生活中的对象.总之,Everything is object! 2.平台 ...