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中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...
随机推荐
- [转]微信JSAPI 微信内置JSAPI 2015年1月官方正式API接口,分享完整实例
FROM : http://www.oschina.net/code/snippet_2276613_45290 HTML通过微信,分享朋友圈出发此JSAPI <?php require_onc ...
- 从客户端(ctl00$ContentPlaceHolder1$result="<?xml version="1.0" ...")中检测到有潜在危险的 Request.Form 值。
ylbtech-Error-WebForm:从客户端(ctl00$ContentPlaceHolder1$result="<?xml version="1.0" . ...
- 里诺全系列注册机+暗桩patch
一直有坛友私信更新里诺,今天花了一天时间,将里诺全系列更新完毕,权当送给坛友们的新年礼物吧! 全系列开放至元旦假期结束,后面就随机开放了. <ignore_js_op> 使用说明: 1.选 ...
- linux 比较两个文件夹不同 (diff命令, md5列表)
比较文件夹diff,可以直接使用diff命令 [root@~]# diff -urNa dir1 dir2 -a Treat all files as text and compare them li ...
- 解决Keyboard遮盖输入的几种办法
一般来说,键盘遮挡主要有这么几种情况,一个是遮住UITextView,还有就是遮住UITextField,一般来说,比较推荐在UIScrollView或者UITableView里加入textfield ...
- 添加 Github follow、star按钮到网页
怎么把github的star/fork/watch三个按钮弄到自己网站上? 就是这个按钮如何弄到我的网站里面来,是否有API呢?mdo/github-buttons · GitHub这个超级方便已经添 ...
- POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线
从TLE的暴力枚举 到 13313MS的扫描线 再到 1297MS的简化后的扫描线,简直感觉要爽翻啦.然后满怀欣喜的去HDU交了一下,直接又回到了TLE.....泪流满面 虽说HDU的时限是2000 ...
- mongodb自动关闭:页面文件太小,无法完成操作
在一台两G内存的win server 2008电脑上运行一个程序,一段时间后mongod自动停止,发现日志文件最后有这样的错误: 2014-11-30T00:32:32.914+0800 [conn3 ...
- 关于Spring mvc 一次请求Controller执行两次的问题
资源路径为空时也会导致重复请求.< span style="background-image:url('');" >相关推荐< /span >,此时就会出现 ...
- [Functional Programming] Arrow Functor with contramap
What is Arrow Functor? Arrow is a Profunctor that lifts a function of type a -> b and allows for ...