2010-02-22 60 views
1

我想了解ColdFusion,因为我来自ASP.NET。我已经把样张,背负了一些已经完成的代码 - 但我似乎无法得到从对象的实际数据,我创建:如何在ColdFusion中编写文本?

<cfset objProduct = createObject("component", "com.MyObj.Product")> 
<cfset prodExists = objProduct.getProduct(10)> 
<html> 
<head/> 
<body> 
<h2>#objProduct.ProductName#</h2> 
</body> 

...它只是打印文字#objProduct.ProductName#文本,而不是来自对象内的数据。任何想法我会误入歧途?

谢谢!

回答

7

别忘了<cfoutput>

<cfoutput> 
<html> 
    <head> 
    <title>Test</title> 
    </head> 
    <body> 
    <h2>#HtmlEditFormat(objProduct.ProductName)#</h2> 
    </body> 
</html> 
</cfoutput> 
+1

另外,不要忘记'HTMLEditFormat()'。这是XSS攻击甚至存在的唯一原因 - 人们经常忘记HTML以逃避他们的输出。所以...这应该是'#HTMLEditFormat(objProduct.ProductName)#',实际上。 – Tomalak 2010-02-23 13:56:37

+0

@Tomalak感谢您的提示。 – yfeldblum 2010-02-23 14:52:56

+0

@tomalak我想了解更多关于HTMLEditFormat()的具体信息以及为什么应该使用它。你能提供一个链接到特定的信息,使没有这个标签输出文本这样一个可怕的想法? – 2012-02-03 15:13:27

1
  1. 你忘了CFOUTPUT标签。
  2. 您试图输出错误的变量。

    #objProduct.getProduct(10)#

<cfoutput>#prodExists#</cfoutput>