httpRequest对象常用的方法
IT程序员开发必备-各类资源下载清单,史上最全IT资源,个人收藏总结!
1. 获得客户机信息
getRequestURL方法返回客户端发出请求时的完整URL。
getRequestURI方法返回请求行中的资源名部分。
getQueryString 方法返回请求行中的参数部分。
getRemoteAddr方法返回发出请求的客户机的IP地址
getRemoteHost方法返回发出请求的客户机的完整主机名
getRemotePort方法返回客户机所使用的网络端口号
getLocalAddr方法返回WEB服务器的IP地址。
getLocalName方法返回WEB服务器的主机名
getMethod得到客户机请求方式
2.获得客户机请求头
getHeader(string name)方法
getHeaders(String name)方法
getHeaderNames方法
3. 获得客户机请求参数(客户端提交的数据)
getParameter(name)方法
getParameterValues(String name)方法
getParameterNames方法
getParameterMap方法
例子程序:
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- System.out.println("getRequestURL: "+request.getRequestURL());
- System.out.println("getRequestURI: "+request.getRequestURI());
- System.out.println("getQueryString: "+request.getQueryString());
- System.out.println("getRemoteAddr: "+request.getRemoteAddr());
- System.out.println("getRemoteHost: "+request.getRemoteHost());
- System.out.println("getRemotePort: "+request.getRemotePort());
- System.out.println("getRemoteUser: "+request.getRemoteUser());
- System.out.println("getLocalAddr: "+request.getLocalAddr());
- System.out.println("getLocalName: "+request.getLocalName());
- System.out.println("getLocalPort: "+request.getLocalPort());
- System.out.println("getMethod: "+request.getMethod());
- System.out.println("-------request.getParamterMap()-------");
- //得到请求的参数Map,注意map的value是String数组类型
- Map map = request.getParameterMap();
- Set<String> keySet = map.keySet();
- for (String key : keySet) {
- String[] values = (String[]) map.get(key);
- for (String value : values) {
- System.out.println(key+"="+value);
- }
- }
- System.out.println("--------request.getHeader()--------");
- //得到请求头的name集合
- Enumeration<String> em = request.getHeaderNames();
- while (em.hasMoreElements()) {
- String name = (String) em.nextElement();
- String value = request.getHeader(name);
- System.out.println(name+"="+value);
- }
- }
浏览器上地址栏:http://localhost:8080/RequestAndResponse/requestmethod?name=sunjob&password=123456&password=haha
控制台输出:
- getRequestURL: http://localhost:8080/RequestAndResponse/requestmethod
- getRequestURI: /RequestAndResponse/requestmethod
- getQueryString: name=sunjob&password=123456&password=haha
- getRemoteAddr: 127.0.0.1
- getRemoteHost: 127.0.0.1
- getRemotePort: 2374
- getRemoteUser: null
- getLocalAddr: 127.0.0.1
- getLocalName: localhost
- getLocalPort: 8080
- getMethod: GET
- -------request.getParamterMap()-------
- name=sunjob
- password=123456
- password=haha
- --------request.getHeader()--------
- host=localhost:8080
- user-agent=Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0
- accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
- accept-language=zh-cn,en-us;q=0.8,zh;q=0.5,en;q=0.3
- accept-encoding=gzip, deflate
- connection=keep-alive
- cache-control=max-age=0
httpRequest对象常用的方法的更多相关文章
- javascript中字符串对象常用的方法和属性
前言 字符串是一种非常重要的数据类型,在Java等面向对象编程语言中,它代表对象类型,而在javascript中它却是一种基本数据类型,在开发的领域中,我们经常会碰到,无论是前端还是后台.比如后台验证 ...
- Array 对象常用的方法总结
shift:删除原数组的第一项,返回删除元素的值:如果数组为空则返回undefined var arr = [1, 2, 3, 4, 5]; var out = arr.shift(); consol ...
- JavaScript操作Array对象常用的方法
转换方法 因为JavaScript内部机制(继承),所有的对象都具有toLocalString() .toString().valueOf()方法,Array也不例外so:var colors = ...
- 日期Date 对象常用的方法
var mydate = new Date();//通过new方法创建对象 //alert(Date()); // 返回一个完整的日期时间 // alert(mydate.getDay());//返回 ...
- JS中String对象常用的方法
1. stringObject.charAt(index) 参数:index 必需,即字符在字符串中的下标. 返回值: 返回在指定位置的字符.返回的字符是长度为 1的字符串.(length属性 ...
- javascript console对象 常用的方法
console对象 var o = {name:'3'} console.assert(o.name === '3', "name 的值应该为:string 3"); consol ...
- Math内置对象 常用的方法
属性: Math.Pi 方法: Math.max() 最大值 Math.min() 最小值 Math.ceil() 向上取整 Math.floor() 向下取整 Math.random() ...
- Mongodb For C# "Query" 对象常用的方法
Query.All("name", "a", "b");//通过多个元素来匹配数组 Query.In("name", & ...
- String对象中常用的方法
String对象中常用的方法 1.charCodeAt方法返回一个整数,代表指定位置字符的Unicode编码.strObj.charCodeAt(index)说明:index将被处理字符的从零开始 ...
随机推荐
- 十二、BOOL冒泡
int main(){ int a[5] = {5,2,3,4,1}; //需要一个可以告诉我们没有交换的东西 //YES:交换 //NO:未交换 ...
- Aspose 导出excel小demo
//转为pdf private void CelltoPDF(string cellPath, string pdfPath) { Workbo ...
- android support Percent支持库开发
Android的布局支持百分比的设置进行开发,来学习如何去实现它,不过看起来会像网页的设置,比如宽度的设置属性是`layout_widthPercent`.在此之前,我们一般都会设置Linearlay ...
- javascript_22_for_js控制div每五个换一行
2. 3. css: <style type="text/css"> div{height: 50px; width: 50px; background: #f1161 ...
- Matlab与微积分计算
一.极限问题的解析解 1.1 单变量函数的极限 格式1: L= limit( fun, x, x0) 格式2: L= limit( fun, x, x0, ‘left’ 或 ‘right’) > ...
- 01-08-01【Nhibernate (版本3.3.1.4000) 出入江湖】NHibernate中的三种状态
以下属于不明来源资料: 引入 在程序运行过程中使用对象的方式对数据库进行操作,这必然会产生一系列的持久化类的实例对象.这些对象可能是刚刚创建并准备存储的,也可能是从数据库中查询的,为了区分这些对象,根 ...
- Unity3D角色攻击范围判定和攻击判定
原地址:http://www.unity蛮牛.com/blog-1801-479.html 第一种方法:运用点乘 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 ...
- Indent Guides VS 插件 对齐线
- .NET中数据集的强类型化
我们知道,每一种程序设计语言都提供一定的类型检查,类型检查可以在编译时进行,也可以在运行时进行,分别称做静态类型检查和动态类型检查.由于静态类型的检查是在编译时进行,实现比较容易,能提高程序的运行效率 ...
- HDU 1753 大明A+B(字符串模拟,简单题)
简单题,但要考虑一些细节: 前导0不要,后导0不要,小数长度不一样时,有进位时,逆置处理输出 然后处理起来就比较麻烦了. 题目链接 我的代码纯模拟,把小数点前后分开来处理,写的很繁杂,纯当纪念——可怜 ...