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中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...
随机推荐
- 在OneNote中快速插入当前日期和时间
做笔记,难免有时需要记录当时的时间,记住这个快捷键会让记笔记的效率提升一点. To insert the current date and time, press Alt+Shift+F. To in ...
- Android开发Tips(5)
欢迎Follow我的GitHub, 关注我的CSDN. 介绍关于Android的一些有趣的小知识点. 本文是第五篇了, 差点儿一周一篇, 欢迎阅读. 其余第一篇, 第二篇, 第三篇, 第四篇. 1. ...
- Socket请求和Http请求的各自特点、区别及适用场景 (转)
http://blog.csdn.net/hexinli/article/details/50500316 Socket实现服务器与客户端之间的物理连接,并进行数据传输.主要有TCP/UDP两个协议. ...
- WordPress 在function.php 文件中方法中the_XXX方法失效
最近在使用WP给客户做一个企业网站,却出现从未遇到的问题. 事件是这样子的:我在function.php文件里写了一个根据分类ID获取文章的文章,因为该方法里的html元素是在多个页面共用的 但我在i ...
- MySQL数据库localhost的root用户登陆遭遇失败
问题:Access denied for user 'root'@'localhost' (using password: YES)打开MySQL目录下的my.ini文件(Linux的话是/etc/m ...
- IIS 7.5: HOW TO ENABLE TLS 1.1 AND TLS 1.2
In IIS 7.5, which is installed on Windows 2008 R2 servers, only SSL 3.0 and TLS 1.0 are enabled for ...
- Node.js中 express-session的奇怪问题
var session = require('express-session'); app.use(cookieParser()); 行 登录以后访问的时候有时候会报这样的错误: The la ...
- ASP入门(二十二)-连接数据库
ADO 简介 在 ASP 中访问数据库使用的 ADO 组件. ADO 是一项微软的技术. ADO 指 ActiveX 数据对象(ActiveX Data Objects). ADO 是微软的 Acti ...
- OpenGL ES 3.0之Fragment buffer objects(FBO)详解(二)
我们可以使用帧缓冲对象来实现离屏渲染.帧缓冲对象支持下列操作 1.只使用OpenGL ES 函数创建帧缓冲区对象. 2.使用EGL context创建多个FBO. 3.创建离屏颜色.深度.模板渲染缓冲 ...
- [Canvas]更多的球
欲观看动态效果请点此下载代码并用Chrome或者Firefox打开. 图例: 代码: <!DOCTYPE html> <html lang="utf-8"> ...