输出URL中的变量

时间:2014-04-23 21:01:30

标签: coldfusion

我想在URL中以变量的形式打印我自己的日期:

我有以下网址:

<cfset urladdress = "https://abc.xyz.com/start_date=2013-04-01&end_date=2014-04-22&data_type=123"> 

我的日期设置如下:

<cfparam name="startdate" default="#DateFormat(dateAdd('d',-1,now()), 'yyyy-mm-dd')#">
<cfparam name="enddate" default="#DateFormat(dateAdd('d',0,now()), 'yyyy-mm-dd')#">

现在,我正在尝试按以下方式打印它:

<cfset urladdress = "https://abc.xyz.com/start_date="<cfoutput>#startdate#</cfoutput>"&end_date="<cfoutput>#enddate#</cfoutput>"&data_type=123">

我得到以下错误:

 Invalid CFML construct found on line 19 at column 123.
ColdFusion was looking at the following text:

<

The CFML compiler was processing:

    < marks the beginning of a ColdFusion tag.Did you mean LT or LTE?
    A cfset tag beginning on line 19, column 2.

我是否需要使用URLEncoded格式化功能?

1 个答案:

答案 0 :(得分:5)

<cfoutput>

中不需要<cfset>
<cfset urladdress = 
  "https://abc.xyz.com/start_date=#startdate#&end_date=#enddate#&data_type=123">

您应该在变量周围使用encodeForURL()(仅限cf10 +)或urlEncodedFormat()来保证安全。

如果您想在CF9中使用encodeForURL(),请查看: https://github.com/misterdai/cfbackport