Archive for the ‘ColdFusion’ Category

Redirecting in CFscript - CFML cflocation equivalent

Wednesday, December 5th, 2007

In CFML you go:

<cflocation url="http://google.co.uk/">

with an additional “addtoken” attribute if needed.

Cflocation can be used both for external and local redirects, so you might as well want to have something like this:

<cflocation url="/section/page.cfm">

In cfscript there is no native equivalent function so you basically have two options. Either write a little wrapper UDF (using the CFML language) for the cflocation tag or take advantage of the GetPageContext function. If you want to replicate the cflocation behaviour in exactly the same way as it is in CFML, you can pick:

GetPageContext().getResponse().sendRedirect("LOCAL PATH OR URL");

AFAIK this hits the web server twice so for local redirections the forward method is a better solution:

GetPageContext().forward("LOCAL PATH");

The examples above have been tested on BlueDragon JX 7.0 on SUSE Linux.