Skip navigation
Currently Being Moderated

cfset in html page

May 27, 2012 2:36 AM

Tags: #html #cfset

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

 
Replies
  • Currently Being Moderated
    May 27, 2012 3:13 AM   in reply to doug777

    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

     
    |
    Mark as:
  • Currently Being Moderated
    May 27, 2012 3:46 AM   in reply to doug777

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 4:48 AM   in reply to doug777

    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

     
    |
    Mark as:
  • Currently Being Moderated
    May 28, 2012 8:12 AM   in reply to doug777

    doug777 wrote:

     

    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>

     

    The original error message was probably justified. Your Javascript indeed has no variable called arAcceptLanguage. What about something like this:

     

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

    <cfset countryCode = lCase(mid(arAcceptLanguage, 4, 2))>

    <cfoutput>

        <cfif arAcceptLanguage EQ "">

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

                var countryCode = "us";

            </script>

        <cfelse>

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

                   /* Define Javascript variables based on ColdFusion variables*/            

                   var #toScript(countryCode, "countryCode")#;

                   var #toScript(arAcceptLanguage, "arAcceptLanguage")#;

            </script>

        </cfif>

    </cfoutput>

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 12:24 AM   in reply to doug777

    doug777 wrote:

     

    ... I don't know how to simulate a crawler in our local environment...

     

    Easy: install HTTrack.

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 12:33 AM   in reply to doug777

    doug777 wrote:

     

    I have changed to your code and also changed the arAcceptLanguage variable to accLang (we thought there might be a caching problem), but the result is unchanged.

     

    Then rule  out caching. For example, place the following code at the top of the page, and see what happens.

     

    <cfheader name="Cache-Control" value="no-cache,no-store,must-revalidate">

    <cfheader name="Pragma" value="no-cache">

    <cfheader name="Expires" value="-1">

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 12:56 AM   in reply to doug777

    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-Lang uage")>

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

     

     

     

     

     

     

     

    Updated by BKBK

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 1:11 AM   in reply to doug777

    !

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points