Skip to main content
Inspiring
May 27, 2012
Answered

cfset in html page

  • May 27, 2012
  • 2 replies
  • 4043 views

I have an html home page but wish to add some cf (CF9).

So I change the page name to index.cfm and add at line 1 :

<cfset arAcceptLanguage = GetPageContext().getRequest().getHeader("Accept-Language")>

This is later used by a javascript function.

It works fine and the browsers show everything correctly and all the javascript runs no problem.

But now some spiders cannot access the page. They get an error 500 and the error is

Error Occurred While Processing Request Variable ARACCEPTLANGUAGE is undefined.

The website is www.booxotel.com and the spider simulator I used is at

http://www.webconfs.com/search-engine-spider-simulator.php

Can anybody offer any clues how I can solve this?

Doug

This topic has been closed for replies.
Correct answer BKBK

I'm wondering if this is a timing problem. Is it possible that the response from the jvm to getRequest().getHeader("Accept-Language") is quick enough for a browser, which resolves the page later, but too slow for a crawler, which requires immediate resolution?

Doug


doug777 wrote:

I'm wondering if this is a timing problem. Is it possible that the response from the jvm to getRequest().getHeader("Accept-Language") is quick enough for a browser, which resolves the page later, but too slow for a crawler, which requires immediate resolution?

I think, when it goes wrong, the variable is simply not defined. What about testing with something like this:

<cfset arAcceptLanguage=GetPageContext().getRequest().getheader("Accept-Language")>

<cfparam name="arAcceptLanguage" default="en-US,nl-NL;q=0.5">

Updated by BKBK

2 replies

BKBK
Community Expert
Community Expert
May 27, 2012

doug777 wrote:

<cfset arAcceptLanguage = GetPageContext().getRequest().getHeader("Accept-Language")>

This is later used by a javascript function.

How do you pass the ColdFusion variable to Javascript? By means of the toScript function perhaps?

The ColdFusion variable belongs to the server, whereas Javascript variables belong to the client. It can easily happen that the user-agent(browser or robot) reloads the page, hence the Javascript, without contacting the server.

doug777Author
Inspiring
May 28, 2012

It is passed to javascript like this:

<cfoutput>

    <cfif arAcceptLanguage EQ "">

        <script language="JavaScript" type="text/javascript">

            var countryCode = "us";

        </script>

    <cfelse>

        <cfset arAcceptLanguage = arAcceptLanguage.Split(",")>

        <script language="JavaScript" type="text/javascript">

            var countryCode = "#LCase(Mid(arAcceptLanguage[1]&"-"&Left(arAcceptLanguage[1], 2), 4, 2))#";

        </script>

    </cfif>

</cfoutput>

doug777Author
Inspiring
May 28, 2012

Sorry the code I posted is not the correct code - it should be:

<cfoutput>

    <cfif arAcceptLanguage EQ "">

        <script language="JavaScript" type="text/javascript">

            var countryCode = "us";

        </script>

    <cfelse>

        <script language="JavaScript" type="text/javascript">

            var countryCode = "#LCase(Mid(arAcceptLanguage, 4, 2))#";

        </script>

    </cfif>

</cfoutput>

This code is what is actually on the server. As I said before, it works correctly, but causes the 500 error and it looks as though the error occurs not at the cfset line or at the cfif line, but at line 8 in this snippet.

Inspiring
May 27, 2012

Well the error message itself pretty much tells you the first thing to do to start troubleshooting this:

Variable ARACCEPTLANGUAGE is undefined. Resources: Enable Robust Exception Information to provide greater detail about the source of errors.

That's what you should be doing.

--

Adam

doug777Author
Inspiring
May 28, 2012

Unfortunately, this is running on a shared server and the host has the Robust Exception permanently switched off.

Inspiring
May 28, 2012

Unfortunately, this is running on a shared server and the host has the Robust Exception permanently switched off.

Do you not have a dev environment that is under your control?

You should be able to emulate whatever that spider-test-site thing does, and replicate this on dev.

--

Adam