Being able to access the properties of the underlying JVM is one of the most basic, and useful, benefits of running ColdFusion on a J2EE system. However, I’ve responded to many people who are new to this deployment about how to access them.
It couldn’t be simpler. Let’s start off with seeing everything that’s available in the java.lang.System structure. Put this code in a blank CFM page.
<cfscript>
j2eeSystem = createobject("java", "java.lang.System");
</cfscript>
<cfdump var="#j2eeSystem#">
Now you’ll see a large dump to your browser with structure key names like Err, In, Out, Properties and others. The most useful of these is the Properties structure. You’ll see as you browser the keys of Properties that some keys are basic JVM keys such as java.class.path and java.runtime.version. So to access a specific value of the Properties structure, your code would be…
<cfscript>
j2eeSystem = createobject("java", "java.lang.System");
javaVendor = sys.Properties['java.specification.vendor'];
</cfscript>
<cfdump var="#javaVendor#">
You can get all kinds of information about the current state of the JVM by accessing these keys. Here’s a fun bit of code. Granted, these values are readily available in the CGI scope of ColdFusion, but it gives you an idea of how to access values from the underlying J2EE system.
<cfscript>
writeOutput("Request URI: " &
GetPageContext().getFusionContext().request.getRequestURI());
writeOutput("<br/>Request URL: " &
GetPageContext().getFusionContext().request.getRequestURL());
writeOutput("<br/>Request Context Path :" &
GetPageContext().getFusionContext().request.getContextPath());
writeOutput("<br/>Request getQueryString :" &
GetPageContext().getFusionContext().request.getQueryString());
writeOutput("<br/>Request getRemoteAddr :" &
GetPageContext().getFusionContext().request.getRemoteAddr());
writeOutput("<br/>Request LocalName :" &
GetPageContext().getFusionContext().request.getLocalName());
writeOutput("<p>COOKIES</p> ");
cookies = arraynew(1);
cookies = GetPageContext().getFusionContext().request.getCookies();
for (i=1; i lt arraylen(cookies); i=i+1)
{
name = cookies[i].getName();
value = cookies[i].getValue();
writeOutput("#name# = #value#<br/>");
}
</cfscript>


