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中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...
随机推荐
- SecureCRT SSH 语法高亮
主要原因 1.term类型不对,不支持彩色.在secureCRT上设置 Options->SessionOptions ->Emulation,然后把Terminal类型改成xterm,并 ...
- apache+jetty 配置web jsp服务器负载均衡
首先,查找中文资料,貌似很少,有一个网友写了点,但是1版本过老,2有些地方有错误. 经过我自己摸索,记录一下.这个图很简洁明了 第一阶段 ,配置jetty 首先从 http://download.ec ...
- SharePoint 列表权限控制
一提到sharepoint 我相信权限控制一定会是一个很重要的话题,尤其是对列表的权限控制,创建.修改.查看权限.其实网上这方面的资料已经很多了,尤其是以下2篇文章,后来索性把CodeArt_Perm ...
- Logistic Regression总结
转自:http://blog.csdn.net/dongtingzhizi/article/details/15962797 Logistic回归总结 作者:洞庭之子 微博:洞庭之子-Bing (20 ...
- javascript定义对象写法
javascript定义对象的几种简单方法 1.构造函数方式,全部属性及对象的方法都放在构造方法里面定义 优点:动态的传递参数 缺点:每创建一个对象就会创建相同的方法函数对象,占用大量内存 funct ...
- mybatis 是如何与数据表对应上的 ?
MyBatis也需要进行表和实体 的关联.我们查询的是表,返回的结果是实体类.这之间有一个对应关系. 如果说实体类的属性和表的列名一一对应,名字一样,那就自动解决了这个问题.但是如果实体类的属性和表的 ...
- ASP入门(九)-Request对象小案例
我们将制作一个能够记住访问者姓名的页面,在这个小案例中,你将学会如何使用Request对象的Cookies.Form以及ServerVariables集合的值,还可以学习到如何使用Response对象 ...
- ASP入门(四)-VBScript的流程控制语句
VBScript条件语句 我们可以使用四种条件语句 If - Then - 语句 If - Then - Else 语句 If - Then - ElseIf 语句 Select - Case 语句 ...
- [Canvas]更多的球
欲观看动态效果请点此下载代码并用Chrome或者Firefox打开. 图例: 代码: <!DOCTYPE html> <html lang="utf-8"> ...
- tomcat7部署多个web应用不同编码,端口
1个tomcat部署多个web应用可以设置不同编码,端口,server.xml配置如下: <?xml version='1.0' encoding='utf-8'?><Server ...