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将被处理字符的从零开始 ...
随机推荐
- perl 脚本测试
原文地址: http://blog.csdn.net/johnny710vip/article/details/8905239 这是一篇关于perl脚本测试的总结性文章,其中提到了很多实用的 ...
- 登录超时自动退出,计算时间差-b
// 此方法适用于所有被创建过的controller,且当前controller生命周期存在,如有错误的地方望大神斧正 // 说一下我们的需求和实现原理,需求:在点击home键退出但没有滑飞它,5分 ...
- java笔记之类和对象
现在编程的思想分成了两大阵营,面向过程和面向对象.现在谈谈啥是面向对象. 作为一只单身狗,谈“对象”还是很伤心很伤心的(:′⌒`)...... 先看看百度怎么说? 好吧,百度说的太抽象,我换个简单的说 ...
- shell脚本积累
统计当前目录下文件夹的大小 for d in $(ls) do du -sh ./$d done 获取之前日期date +"%Y%m%d" -d "-n days&q ...
- Eclipse maven工程 Missing artifact com.sun:tools:jar:1.5.0:system 解决方法
今天同事在使用eclipse,引入一个新的maven工程时报错: Missing artifact com.sun:tools:jar:1.6.0:system 这个问题很奇怪,相同的代 ...
- 【BZOJ】【2179】FFT快速傅里叶
FFT 做的第二道用到FFT的……好吧其实还是模板题-_-b 百度上说好像分治也能做……不过像FFT这种敲模板的还是省事=.= /*********************************** ...
- [设计模式] 22 模板方法模式 template
转http://www.jellythink.com/archives/407 在GOF的<设计模式:可复用面向对象软件的基础>一书中对模板方法模式是这样说的:定义一个操作中的算法骨架,而 ...
- Castle 开发系统文章
转: http://www.cnblogs.com/Jebel/archive/2008/06/24/1228766.html
- 8个月从CS菜鸟到拿到Google Offer的经历+内推
http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=77453&page=1&authorid=10377 ...
- Android 监听ListView、GridView滑动到底部
// 监听listview滚到最底部 mIndexList.setOnScrollListener(new OnScrollListener() { @Override public void onS ...