In XPages, CGI variables are also available, but you need to write some code to get them via the JSF context.

Here is a complete, functional JavasScript example of how to get and print the remote address of the incoming browser request:

print("Remote Address: " + facesContext.getExternalContext().getRequest().getRemoteAddr());

This server-side JavaScript library makes most useful CGI variables conveniently available in a new "CGIVariables" JavaScript object:

/* 
      This server-side JavaScript library implements a class named "CGIVariables" which allows for easy access 
      to most CGI variables in XPages via JavaScript. 
      For example, to dump the remote users name, IP address and browser string to the server console, use: 

      var cgi = new CGIVariables(); 
      print ("Username: " + cgi.REMOTE_USER); 
      print ("Address : " + cgi.REMOTE_ADDR); 
      print ("Browser : " + cgi.HTTP_USER_AGENT); 
              
      Written July 2008 by Thomas Gumz, IBM. 
*/ 

function CGIVariables() { 

      // setup our object by getting refs to the request and servlet objects         
      try { 
              this.request = facesContext.getExternalContext().getRequest(); 
              this.servlet = facesContext.getExternalContext().getContext(); 
      } catch(e) { 
              print (e.message); 
      } 

      this.prototype.AUTH_TYPE            = this.request.getAuthType(); 
      this.prototype.CONTENT_LENGTH       = this.request.getContentLength(); 
      this.prototype.CONTENT_TYPE         = this.request.getContentType(); 
      this.prototype.CONTEXT_PATH         = this.request.getContextPath(); 
      this.prototype.GATEWATY_INTERFACE   = "CGI/1.1"; 
      this.prototype.HTTPS                = this.request.isSecure() ? "ON" : "OFF"; 
      this.prototype.PATH_INFO            = this.request.getPathInfo(); 
      this.prototype.PATH_TRANSLATED      = this.request.getPathTranslated(); 
      this.prototype.QUERY_STRING         = this.request.getQueryString(); 
      this.prototype.REMOTE_ADDR          = this.request.getRemoteAddr(); 
      this.prototype.REMOTE_HOST          = this.request.getRemoteHost(); 
      this.prototype.REMOTE_USER          = this.request.getRemoteUser(); 
      this.prototype.REQUEST_METHOD       = this.request.getMethod(); 
      this.prototype.REQUEST_SCHEME       = this.request.getScheme(); 
      this.prototype.REQUEST_URI          = this.request.getRequestURI(); 
      this.prototype.SCRIPT_NAME          = this.request.getServletPath(); 
      this.prototype.SERVER_NAME          = this.request.getServerName(); 
      this.prototype.SERVER_PORT          = this.request.getServerPort(); 
      this.prototype.SERVER_PROTOCOL      = this.request.getProtocol(); 
      this.prototype.SERVER_SOFTWARE      = this.servlet.getServerInfo(); 

      // these are not really CGI variables, but useful, so lets just add them for convenience 
      this.prototype.HTTP_ACCEPT          = this.request.getHeader("Accept"); 
      this.prototype.HTTP_ACCEPT_ENCODING = this.request.getHeader("Accept-Encoding"); 
      this.prototype.HTTP_ACCEPT_LANGUAGE = this.request.getHeader("Accept-Language"); 
      this.prototype.HTTP_CONNECTION      = this.request.getHeader("Connection"); 
      this.prototype.HTTP_COOKIE          = this.request.getHeader("Cookie");         
      this.prototype.HTTP_HOST            = this.request.getHeader("Host");         
      this.prototype.HTTP_REFERER         = this.request.getHeader("Referer"); 
      this.prototype.HTTP_USER_AGENT      = this.request.getHeader("User-Agent"); 
}

You can also find this server-side JavaScript library in the Domino 8.5 "discussion8.ntf" template as "xpCGIVariables..jss". 
Below is a sample XPage which uses the script library to print some CGI variables to the server console:

<?xml version="1.0" encoding="UTF-8"?> 
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" 
      xmlns:xc="http://www.ibm.com/xsp/custom" createForm="false"> 
      <xp:this.resources> 
              <xp:script src="/xpCGIVariables.jss" clientSide="false"></xp:script> 
      </xp:this.resources> 
      <xp:this.beforePageLoad><![CDATA[#{javascript:var cgi = new CGIVariables(); 
print ("Username: " + cgi.REMOTE_USER); 
print ("Address : " + cgi.REMOTE_ADDR); 
print ("Browser : " + cgi.HTTP_USER_AGENT); 
}]]></xp:this.beforePageLoad> 
</xp:view>



Note: For performance reasons, it is recommended to cache CGI variables (for example, in the sessionScope) once you retrieved the

XPAGES 中CGI变量的获取的更多相关文章

  1. dos中定义变量与获取常见的引用变量以及四则运算、备份文件(set用法)

    在dos中使用set定义变量: set  a=8              (注意等号两边没有空格) 引用变量如: echo  %a%        将打印a的值 (%a%是获取变量a的值) dos中 ...

  2. smarty获取php中的变量

    {$smarty}保留变量不需要从PHP脚本中分配,是可以在模板中直接访问的数组类型变量,通常被用于访问一些特殊的模板变量.例如,直接在模板中访问页面请求变量.获取访问模板时的时间邮戳.直接访问PHP ...

  3. C#中在内容页获取其模板页中的变量,或者值

    在CSDN的博文中看到了 muziduoxi 的文章:http://blog.csdn.net/muziduoxi/article/details/5386543 虽然里面提到的方法没有解决我的难题, ...

  4. 手写面试编程题- 数组去重 深拷贝 获取文本节点 设置奇数偶数背景色 JS中检测变量为string类型的方法 第6题闭包 将两个数组合并为一个数组 怎样添加、移除、移动、复制、创建和查找节点? 继承 对一个数组实现随机排序 让元素水平 垂直居中的三种方式 通过jQuery的extend方法实现深拷贝

    第1题==>实现数组去重 通过 new Set(数组名) // var arr = [12, 12, 3, 4, 5, 4, 5, 6, 6]; // var newarr1 = new Set ...

  5. docker-compose 布署应用nginx中的create-react-app应用获取环境变量

    文章来源:https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-re ...

  6. PHP中环境变量的操作

    在 PHP 中,我们可以通过 phpinfo() 查看到当前系统中的环境变量信息(Environment).在代码中,我们也可以通过两个函数,查看和修改相应的环境变量信息. getenv() 获取环境 ...

  7. Linux中环境变量文件及配置

    Linux中环境变量文件及配置   一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统 ...

  8. 浅谈JavaScript中的变量、参数、作用域和作用域链

    基本类型和引用类型 在JavaScript中有两种数据类型值.基本类型值和引用类型值.基本类型值指的是简单的数据段,而引用类型值指的是可能由多个值构成的对象.在JavaScript中有5种基本数据类型 ...

  9. Linux中环境变量文件及配置(转载)

    一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...

随机推荐

  1. @Autowired注解和静态方法 NoClassDefFoundError could not initialize class 静态类

    NoClassDefFoundError could not initialize class 静态类 spring boot 静态类 java.lang.ExceptionInInitializer ...

  2. 从客户端(SeekingJobs="<B>·</B> 物流规划,<B>·</...")中检测到有潜在危险的 Request.Form 值。

    今天提交各东西发觉出错了,错误信息如下: “/”应用程序中的服务器错误. 从客户端(SeekingJobs="<B>·</B> 物流规划,<B>·< ...

  3. pthread_create 报函数参数不匹配问题

    pthread_create方法遇到类方法时总会报  argument of type ‘void* (Thread::)(void*)’ does not match ‘void* (*)(void ...

  4. 很不错的python 机器学习博客

    http://www.cuijiahua.com/resource.html 曾看过的书,感觉一些很有用的学习资料,推荐给大家! Python基础: 网络教程推荐: 系统学习python3可以看廖雪峰 ...

  5. FastReport.Net 入门

    任何一门编程技术入门体验都是以“Hello World”开始的,但我想再复杂一点的“Hello World”,才能算真正的入门.   FastReport.Net V1.2.76 ,vs2008 在 ...

  6. 鼠标悬浮在img上让图片变大

    样式: <style type="text/css">        img:hover{ transform:scale(1.02,1.02)}</style& ...

  7. OpenFeign封装为springboot starter

    OpenFeign是什么 随着业务的增多,我们的单体应用越来越复杂,单机已经难以满足性能的需求,这时候出现了分布式.分布式通讯除了RPC, REST HTTP请求是最简单的一种方式.OpenFeign ...

  8. Kaggle网站流量预测任务第一名解决方案:从模型到代码详解时序预测

    Kaggle网站流量预测任务第一名解决方案:从模型到代码详解时序预测 2017年12月13日 17:39:11 机器之心V 阅读数:5931   近日,Artur Suilin 等人发布了 Kaggl ...

  9. unity3d Player Settings 中的Stripping Level(剥离等级)对应每个等级具体剥离了哪些库

    http://docs.unity3d.com/410/Documentation/ScriptReference/MonoCompatibility.html

  10. 数据科学家Docker历险记(1):windows下环境搭建

    原文:http://www.xueqing.tv/cms/article/247 Docker是最近炒得很火热的一门技术,在网上可以找到关于它的介绍文章,比如<Docker到底是什么?为什么它这 ...