XPAGES 中CGI变量的获取
In XPages, CGI variables are also available, but you need to write some code to get them via the JSF context.
- First you need to call facesContext.getExternalContext() which returns anhttp://java.sun.com/javaee/javaserverfaces/1.0/docs/api/javax/faces/context/ExternalContext.html" target="_blank">ExternalContext object
- Next, you need to get the http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.html" target="_blank">servlet request by callinggetRequest() on the ExternalContext object
- Then you can call various .getXYZ() methods of the request object to retrieve the values of CGI variables.
For example, to retrieve the remote IP address of a browser session, use request.getRemoteAddr()
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变量的获取的更多相关文章
- dos中定义变量与获取常见的引用变量以及四则运算、备份文件(set用法)
在dos中使用set定义变量: set a=8 (注意等号两边没有空格) 引用变量如: echo %a% 将打印a的值 (%a%是获取变量a的值) dos中 ...
- smarty获取php中的变量
{$smarty}保留变量不需要从PHP脚本中分配,是可以在模板中直接访问的数组类型变量,通常被用于访问一些特殊的模板变量.例如,直接在模板中访问页面请求变量.获取访问模板时的时间邮戳.直接访问PHP ...
- C#中在内容页获取其模板页中的变量,或者值
在CSDN的博文中看到了 muziduoxi 的文章:http://blog.csdn.net/muziduoxi/article/details/5386543 虽然里面提到的方法没有解决我的难题, ...
- 手写面试编程题- 数组去重 深拷贝 获取文本节点 设置奇数偶数背景色 JS中检测变量为string类型的方法 第6题闭包 将两个数组合并为一个数组 怎样添加、移除、移动、复制、创建和查找节点? 继承 对一个数组实现随机排序 让元素水平 垂直居中的三种方式 通过jQuery的extend方法实现深拷贝
第1题==>实现数组去重 通过 new Set(数组名) // var arr = [12, 12, 3, 4, 5, 4, 5, 6, 6]; // var newarr1 = new Set ...
- docker-compose 布署应用nginx中的create-react-app应用获取环境变量
文章来源:https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-re ...
- PHP中环境变量的操作
在 PHP 中,我们可以通过 phpinfo() 查看到当前系统中的环境变量信息(Environment).在代码中,我们也可以通过两个函数,查看和修改相应的环境变量信息. getenv() 获取环境 ...
- Linux中环境变量文件及配置
Linux中环境变量文件及配置 一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统 ...
- 浅谈JavaScript中的变量、参数、作用域和作用域链
基本类型和引用类型 在JavaScript中有两种数据类型值.基本类型值和引用类型值.基本类型值指的是简单的数据段,而引用类型值指的是可能由多个值构成的对象.在JavaScript中有5种基本数据类型 ...
- Linux中环境变量文件及配置(转载)
一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...
随机推荐
- Linux 批量查找替换方法(VIM和sed)
版权声明:欢迎与我交流讨论,若要转载请注明出处~ https://blog.csdn.net/sinat_36053757/article/details/70946263 1.VIM命令 当前行进行 ...
- 短址服务 api
1 is.gd 他这个api简单: http://is.gd/api.php?longurl= 后面加网址就可以返回短址 2 Google URL Shortener API api地址: http ...
- 使用idea 在springboot添加本地jar包的方法
原文地址;https://blog.csdn.net/huxiaodong1994/article/details/80702278 1.首先在与src同级的目录下新建一个lib目录,然后将本地jar ...
- 【转】vs2012-vs2010使用stlport库的配置
http://www.cnblogs.com/sbaicl/archive/2012/08/30/2663114.html STLport下载地址:http://sourceforge.net/pro ...
- 数据库实例: STOREBOOK > 用户 > 编辑 用户: SYS
ylbtech-Oracle:数据库实例: 数据库实例: STOREBOOK > 用户 > 编辑 用户: SYS 编辑 用户: SYS 1. 一般信息返回顶部 1.1, 1.2, ...
- 【转】从QDataStream向QByteArray中写入数据时的注意点(QT)
最近发现从QDataStream向QByteArray中写入数据常常是写不进去的,通过查看QT的源码: QDataStream &operator>>(QDataStream &a ...
- GAN与NLP的讨论
https://www.jianshu.com/p/32e164883eab 这篇文章,GAN与NLP的讨论,可以看看.
- tmux 终端分屏利器使用
介绍 Tmux 是一个工具,用于在一个终端窗口中运行多个终端会话. 不仅如此,你还可以通过 Tmux 使终端会话运行于后台或是按需接入.断开会话,这个功能非常实用. 很好的工具,记录一下,以后要常用. ...
- Convert Sorted List to Binary Search Tree leetcode java
题目: Given a singly linked list where elements are sorted in ascending order, convert it to a height ...
- elasticsearch6.0版本安装head插件
ES6.0版本安装head插件 1.1 前言 不知道是我电脑问题还是最近的开源软件都比较**,mysql和elasticsearch新版本变动都比较大. elasticsearch6.0貌似已经不支持 ...