Skip to main content
Ben Nadel at the jQuery Conference 2009 (Cambridge, MA) with: Cody Lindley
Ben Nadel at the jQuery Conference 2009 (Cambridge, MA) with: Cody Lindley ( @codylindley )

I Don't Understand ColdFusion GetPageContext() And Include()

By on
Tags:

I was pulling my hair out trying to figure out an error I was getting with the following code:

<!--- Include public style sheet. --->
<cfset GetPageContext().Include( "../../../linked/css/main.css" ) />

This line of code kept throwing the error:

java.io.FileNotFoundException

After literally an hour and a half of playing around with "../" combinations and outputting FileExists() results, I switched over to using a CFInclude tag:

<!--- Include public style sheet. --->
<cfinclude template="../../../linked/css/main.css" />

For some reason, this include works, and the include method of the GetPageContext() servlet does NOT work. I have no idea what this means. As I am not a professional Java programmer, I am not familiar with servlets and context objects. I don't know if it has something to do with web-visibility. I know that the include above were crossing over a virtual directory (an admin area was pulling the CSS file from the public site and the admin was in a virtual directory).

Who knows. I tried to Google some information about page context and I came up with this Java class, but that doesn't really help me understand. Maybe someone out there can help.

As part of my mentality, I was doing it this way so that the main.css file would be included without being parsed. As far as I know, a CFInclude tag will actually parse the file looking for ColdFusion code (even in a CSS file). I had no need to parse the file and was told that the Include() method would not do so.

Want to use code from this post? Check out the license.

Reader Comments

1 Comments

"a CFInclude tag will actually parse the file looking for ColdFusion code (even in a CSS file)"

It doesn't unless it's a file with an extension that equates to a Coldfusion template i.e .cfm.

Try it yourself, cfinclude a css file. If CF was trying to parse the file you'd get errors being thrown when it encounters # symbols on styling blocks.

15,377 Comments

James,

Please take a look at the demo that I have set up. I think you are confused about evaluation of # signs vs. parsing of page looking for ColdFusion tags.

http://bennadel.com/index.cfm?dax=blog:250.view

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel