我们经常需要在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. <OFFER03>03_01_DuplicationInArray

    #include<cstdio> bool duplicate(int numbers[], int length, int* duplication) { ) return false; ...

  2. Java8的新特性,二进制序列转十进制数字

    package kata_007_二进制序列转十进制int; /** * java8 Lambda表达式转换binary序列->十进制数 */ import java.util.ArrayLis ...

  3. iis发布,部署

    1.项目发布:选择iis:文件系统:文件路径:realese 2.iis添加: 3.host文件添加 问题1: 不能在此路径中使用此配置节.如果在父级别上锁定了该节,便会出现这种情况.锁定 在全新安装 ...

  4. Tex: The top-level auxiliary file: *.aux I couldn't open style file IEEEtran.bst 解决方法

    参考: Bibliography is not printed using Kile on Ubuntu Tex: The top-level auxiliary file: *.aux I coul ...

  5. 【Coursera】Fifth week(3)

    Ethernet 在 PARC(Xerox) 发明. 第一个 Local-Area-Network (LAN 局域网). 把 PCs 连接到 激光打印机上. 在夏威夷大学,被早期的无线网络 Aloha ...

  6. iBatis的CRUD操作详细总结

    昨天晚上看了一下关于iBatis的一个讲解的视频,讲的和我的这个简单的总结差不多.... 思考了一下还是把主要操作都总结一下吧,当然这里也不是全的,知识简单的CRUD... 首先我觉得持久层的操作主要 ...

  7. shell 使用变量

    使用变量 使用一个定义过的变量,只要在变量名前面加美元符号即可,如: your_name="qinjx" echo $your_name echo ${your_name} 变量名 ...

  8. shell 命令行光标跳转快捷键和history的用法

    Ctrl+a: 跳到命令行首 Ctrl+e: 跳到命令行尾 Ctrl+u: 删除光标至命令行首的内容 Ctrl+k: 删除光标至命令行尾的内容 Ctrl+<- 跳到前一个单词首部 Ctrl+-& ...

  9. java日期操作 大全

    先来一个:  取得指定月份的第一天与取得指定月份的最后一天  http://iamin.blogdriver.com/iamin/847990.html ));             }       ...

  10. Codeforces 38B - Chess

    38B - Chess 思路:懂点象棋的规则就可以,看看哪些点可以放马. 代码: #include<bits/stdc++.h> using namespace std; #define ...