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

最新文章

  1. Chrome必备的扩展
  2. 参数类型params
  3. Python学习笔记-字符串
  4. EventBus vs Otto vs LiteEventBus
  5. [iOS 多线程 &amp; 网络 - 2.3] - 解析xml
  6. Qt Creator编译时:cannot open file &#39;debug\QtGuiEx.exe&#39; File not found
  7. 查看Tomcat版本
  8. hdu_5878_I Count Two Three(预处理)
  9. JS模式--装饰者模式(用AOP动态改变函数的参数)
  10. 【开发技术】web.xml vs struts.xml
  11. 整理一点与排列组合有关的问题[组合数 Stirling数 Catalan数]
  12. SpringMVC-2-(Controller)
  13. 自己搭建anki同步服务器
  14. centos 安装MySQL全过程
  15. JS-事件对象(鼠标键盘事件)
  16. [原创]STM32 BOOT模式配置以及作用
  17. iOS原生的AVFoundation扫描二维码/条形码
  18. Linux之 AWK SED
  19. 嵌入式Linux下Qt的中文显示
  20. asp.net 在自己指定的文件夹下面弄个App.config来读取配置

热门文章

  1. Swift: Swift中Selector的变化
  2. boost并发编程boost::atomic
  3. .net 系列:Expression表达式树、lambda、匿名委托 的使用【转】
  4. 如何在Vblock里配置Boot from SAN
  5. Unique Paths leetcode java
  6. 【使用JSOUP实现网络爬虫】修改数据-设置属性的值
  7. AI-终极算法-遗传算法
  8. wifidog 源码初分析(4)-转
  9. 在centos7.4上安装mysql5.5
  10. Eclipse 文件太长,导致着色异常问题