• 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

  • 相关阅读:
    FusionMap 检测融合基因
    嵌合体序列
    seqtk 的安装和使用
    cutadapt 的安装与使用
    C语言简单选择排序
    C语言冒泡排序
    Java实现的各种排序算法(包括冒泡,快排等)
    C++实现顺序计算输入表达式的值
    java多线程有几种实现方法?线程之间如何同步
    java中==与equal()方法的区别
  • 原文地址:https://www.cnblogs.com/westward/p/5217159.html
Copyright © 2020-2023  润新知