Avg. Rating 4.7

Problem

Are you a ColdFusion developer? Have you ever wanted to get away from using CGI variables such as CGI.SCRIPT_NAME but didn't quite know what else to use?

Solution

Then you might find the following list of CGI variables and their respective ColdFusion/Java Servlet Alternative methods to be helpful because I couldn't find much (if any) documentation on this.

Detailed explanation

CGI Variable ColdFusion / Java Servlet Alternative Method
CGI.AUTH_TYPE getPageContext().getRequest().getAuthType()
CGI.CONTENT_LENGTH getPageContext().getRequest().getContentLength()
CGI.CONTEXT_PATH getPageContext().getRequest().getContextPath()
CGI.CONTENT_TYPE getPageContext().getRequest().getContentType()
CGI.PATH_INFO getPageContext().getRequest().getPathInfo()
CGI.PATH_TRANSLATED getPageContext().getRequest().getPathTranslated()
CGI.QUERY_STRING getPageContext().getRequest().getQueryString()
CGI.REMOTE_ADDR getPageContext().getRequest().getRemoteAddr()
CGI.REMOTE_HOST getPageContext().getRequest().getRemoteHost()
CGI.REMOTE_USER getPageContext().getRequest().getRemoteUser()
CGI.REQUEST_METHOD getPageContext().getRequest().getMethod()
CGI.SCRIPT_NAME getPageContext().getRequest().getServletPath()
CGI.SERVER_NAME getPageContext().getRequest().getServerName()
CGI.SERVER_PORT getPageContext().getRequest().getServerPort()
CGI.SERVER_PORT_SECURE getPageContext().getRequest().isSecure()
CGI.SERVER_PROTOCOL getPageContext().getRequest().getProtocol()
CGI.SERVER_SOFTWARE getPageContext().getRequest().getHeader("Server-Software")
CGI.HTTP_ACCEPT getPageContext().getRequest().getHeader("Accept")
CGI.HTTP_ACCEPT_CHARSET getPageContext().getRequest().getHeader("Accept-Charset")
CGI.HTTP_ACCEPT_ENCODING getPageContext().getRequest().getHeader("Accept-Encoding")
CGI.HTTP_ACCEPT_LANGUAGE getPageContext().getRequest().getHeader("Accept-Language")
CGI.HTTP_CONNECTION getPageContext().getRequest().getHeader("Connection")
CGI.HTTP_COOKIE getPageContext().getRequest().getHeader("Cookie")
CGI.HTTP_HOST getPageContext().getRequest().getHeader("Host")
CGI.HTTP_REFERER getPageContext().getRequest().getHeader("Referer")
CGI.HTTP_USER_AGENT getPageContext().getRequest().getHeader("User-Agent")
 
Other Useful Java Servlets  
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters. getPageContext().getRequest().getRequestURL()
The URL string corresponding to the current client request. The string returned does not include the server name or query arguments. getPageContext().getRequest().getRequestURI()
Returns the name of the scheme used to make this request (http, https, or ftp) getPageContext().getRequest().getScheme()

 

For more information on the Java HttpServletRequest: http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletRequest.html

For more informaiton on HTTP Header Field Definitions, see: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

To view the original article on my blog, please visit: http://www.stephenwithington.com/blog/index.cfm/2008/8/26/CGI-Variables-and-Their-Respective-ColdFusionJava-Servlet-Alternative-Methods


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes