我们经常需要在servlet(j2ee13.jar  javax.servlet.http.HttpServletRequest)中,获取请求request的各种数据信息。

请求的URL:   http://10.63.205.120:7001/undwrt/GetRealIP?param=a

可通过下面代码:

    /**
* 通过servlet获取客户端请求request的URL
* http://10.63.205.120:7001/undwrt/GetRealIP?param=a
* */
protected void getURL(HttpServletRequest request){
int ContentLength= request.getContentLength();
String ContentType= request.getContentType();
String CharacterEncoding= request.getCharacterEncoding();
String AuthType= request.getAuthType();
String Method= request.getMethod();
String RemoteAddr= request.getRemoteAddr();
String PathInfo= request.getPathInfo();
String ServerName= request.getServerName();
String Protocol= request.getProtocol();
String QueryString= request.getQueryString();
String RequestURI= request.getRequestURI();
String Scheme= request.getScheme();
int ServerPort= request.getServerPort();
String ServletPath= request.getServletPath(); String RequestURL= request.getRequestURL().toString();
String ContextPath= request.getContextPath(); System.out.println("ContentLength :"+ContentLength);
System.out.println("ContentType :"+ContentType);
System.out.println("CharacterEncoding :"+CharacterEncoding);
System.out.println("AuthType :"+AuthType);
System.out.println("Method :"+Method);
System.out.println("RemoteAddr :"+RemoteAddr);
System.out.println("PathInfo :"+PathInfo);
System.out.println("ServerName :"+ServerName);
System.out.println("Protocol :"+Protocol);
System.out.println("QueryString :"+QueryString);
System.out.println("RequestURI :"+RequestURI);
System.out.println("Scheme :"+Scheme);
System.out.println("ServerPort :"+ServerPort);
System.out.println("ServletPath :"+ServletPath); System.out.println("RequestURL :"+RequestURL);
System.out.println("ContextPath :"+ContextPath);
}

run as:
ContentLength :-1
ContentType :null
CharacterEncoding :GBK
AuthType :null
Method :GET
RemoteAddr :10.63.205.79
PathInfo :null
ServerName :10.63.205.120
Protocol :HTTP/1.1
QueryString :param=a
RequestURI :/undwrt/GetRealIP
Scheme :http
ServerPort :7001
ServletPath :/GetRealIP
RequestURL :http://10.63.205.120:7001/undwrt/GetRealIP
ContextPath :/undwrt

java request获取各种数据的更多相关文章

  1. 5.1 Request 获取请求数据的几种方法

    //获取请求头和请求数据 //请求数据(1.通过超链接 2.通过表单) //获取请求数据的时候一般来说 都要先检查 再使用 public class RequestDemo2 extends Http ...

  2. EXTJS 资料 Ext.Ajax.request 获取返回数据

    下面是一个登陆页面调用的EXTJS login function,通过 url: '/UI/HttpHandlerData/Login/Login.ashx',获取返回登陆账户和密码! Ext.onR ...

  3. 爬虫小探-Python3 urllib.request获取页面数据

    使用Python3 urllib.request中的Requests()和urlopen()方法获取页面源码,并用re正则进行正则匹配查找需要的数据. #forex.py#coding:utf-8 ' ...

  4. Java如何获取JSON数据中的值

    场景:在接口自动化场景中,下个接口发送的请求参数,依赖上个接口请求结果中的值.需要将获取值作为全局参数引用. import java.io.File; import java.io.FileInput ...

  5. request获取ip数据

    http://www.cnblogs.com/icerainsoft/p/3584532.html

  6. jmeter 性能测试 JDBC Request (查询数据库获取数据库数据) 的使用

    JDBC Request 这个Sampler可以向数据库发送一个jdbc请求(sql语句),并获取返回的数据库数据进行操作.它经常需要和JDBC Connection Configuration配置原 ...

  7. request获取请求头和请求数据

    package cn.itcast.request; import java.io.IOException; import java.io.InputStream; import java.io.Pr ...

  8. jmeter JDBC Request (查询数据库获取数据库数据) 的使用

    JDBC Request 这个Sampler可以向数据库发送一个jdbc请求(sql语句),并获取返回的数据库数据进行操作.它经常需要和JDBC Connection Configuration配置原 ...

  9. 转jmeter 性能测试 JDBC Request (查询数据库获取数据库数据) 的使用

    JDBC Request 这个Sampler可以向数据库发送一个jdbc请求(sql语句),并获取返回的数据库数据进行操作.它经常需要和JDBC Connection Configuration配置原 ...

随机推荐

  1. Python3基础 str *运算 重复拼接字符串

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. sublimeText3最新教程-自带插件汉化(sublime-text_build-3175_amd64)

    一.可用注册码 1.更改dns 在linux下的目录是     /etc/hosts 在win7中,hosts文件的位置:C:\Windows\System32\drivers\etc 127.0.0 ...

  3. 解决Android Studio Conflict with dependency 'com.android.support:support-annotations'报错

    解决Android Studio Conflict with dependency 'com.android.support:support-annotations'报错 在Android Studi ...

  4. BZOJ 1044: [HAOI2008]木棍分割 DP 前缀和优化

    题目链接 咳咳咳,第一次没大看题解做DP 以前的我应该是这样的 哇咔咔,这tm咋做,不管了,先看个题解,再写代码 终于看懂了,卧槽咋写啊,算了还是抄吧 第一问类似于noip的那个跳房子,随便做 这里重 ...

  5. FJNUOJ the greed of Yehan(最长路 + 权值乘积转化)题解

    Description During the trip, Yehan and Linlin pass a cave, and there is a board at the door, which s ...

  6. 第八章 对称加密算法--AES

    注意:本节内容主要参考自<Java加密与解密的艺术(第2版)>第7章“初等加密算法--对称加密算法” 8.1.AES 特点: 密钥建立时间短.灵敏性好.内存需求低(不管怎样,反正就是好) ...

  7. BZOJ2982: combination Lucas

    Description LMZ有n个不同的基友,他每天晚上要选m个进行[河蟹],而且要求每天晚上的选择都不一样.那么LMZ能够持续多少个这样的夜晚呢?当然,LMZ的一年有10007天,所以他想知道答案 ...

  8. UVa 11212 编辑书稿(dfs+IDA*)

    https://vjudge.net/problem/UVA-11212 题意:给出n个自然段组成的文章,将他们排列成1,2...,n.每次只能剪切一段连续的自然段,粘贴时按照顺序粘贴. 思路:状态空 ...

  9. [BZOJ]|[Ural] Formula 1-----插头DP入门

    1519. Formula 1 Time limit: 1.0 secondMemory limit: 64 MB Background Regardless of the fact, that Vo ...

  10. 基于Java的三种对象持久化方式

    1:序列化技术: 序列化的过程就是将对象写入字节流和从字节流中读取对象.将对象状态转换成字节流之后,可以用java.io包中的各种字节流类将其保存到文件中,可以通过管道或线程读取,或通过网络连接将对象 ...