java request获取各种数据
2016-02-25 15:31
381 查看
我们经常需要在servlet(j2ee13.jar javax.servlet.http.HttpServletRequest)中,获取请求request的各种数据信息。
请求的URL: http://10.63.205.120:7001/undwrt/GetRealIP?param=a
可通过下面代码:
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
请求的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
相关文章推荐
- incredibuild 命令行 error D8037
- 用数据库连接池解决org.hibernate.exception.JDBCConnectionException:could not execute query
- Ultra-QuickSort(树状数组求逆序对数)
- IOS之UITabBarController
- 基于pt-query-digest的慢查询日志持续追踪 推荐
- 从源代码安装Guidance
- ./configure: error: the GeoIP module requires the GeoIP library.
- 《iOS Human Interface Guidelines》——The Status Bar
- UIResponder
- Formal System-相继式演算(Sequenz)
- iOS开发系列--UITableView全面解析
- queue
- execute、executeupdate、executequery三者的区别
- Google推出iOS功能性UI测试框架EarlGrey
- Leetcode 225:Implement Stack using Queues
- iOS的UDID废用以及UUID配合keychain的替换方案实现
- 彻底抛弃脚本录制,LR脚本之使用web_custom_request函数自定义
- iPhone开发之UIView中的动画属性
- iOS之UIScrollView循环滚动
- ${pageContext.request.contextPath} JSP取得绝对路径