zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    创建型设计模式-原型模式(单例) MemberwiseClone()
    Oracle 查看没有释放的链接 和删除,相关sql
    win10 安装 SQL Developer 工具
    修改nuget包默认存放路径 win10
    使用端口查询
    未能加载文件或程序集“Newtonsoft.Json, Version=12.0.0.0,
    微信错误码
    sqlserver 时间转换记录
    Homebrew 使用指南
    在Mac检查安装的.net core 版本
  • 原文地址:https://www.cnblogs.com/westward/p/5217159.html
Copyright © 2011-2022 走看看