java request获取各种数据

我们经常需要在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

 

转载于:https://www.cnblogs.com/westward/p/5217159.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值