Coldfusion url变量问题
有时我们会传递 url 字符串,如下所示:
http://www.oursite.com/index.cfm?layout=displayNews&newsArticle=1837
注意 url 中的 "&"
。这会导致接收页面出现问题,该页面将 url 变量视为 url.AMP;newsArticle
我们无法始终控制它是以这种方式到达还是以“&”形式到达。
在接收页面中,我们希望处理任一格式可能到达的可能性。我做了一些无效的尝试,例如
<cfif structkeyexists(url,'AMP;NEWSARTICLE')>
<cfset url.newsArticle = evaluate('#url.AMP;NEWSARTICLE#')> <!--- this line errors on the semicolon after AMP --->
</cfif>
任何指针都非常感谢。
Sometimes we are passing url strings such as follows:
http://www.oursite.com/index.cfm?layout=displayNews&newsArticle=1837
Notice the "&"
in the url. This causes issues on the receiving page, which sees the url variable as url.AMP;newsArticle
We cannot always control whether it arrives this way or as "&".
In the receiving page, we would like to deal with the possibility that either format may arrive. I've made a few weak attempts that don't work, e.g.
<cfif structkeyexists(url,'AMP;NEWSARTICLE')>
<cfset url.newsArticle = evaluate('#url.AMP;NEWSARTICLE#')> <!--- this line errors on the semicolon after AMP --->
</cfif>
Any pointers greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
替换 cgi.query_string 中的字符串不会解决问题,因为此时 URL 范围已填充。
您可以将值作为结构引用:
因此,将其与 structKeyExists 结合起来:
进一步扩展,您可以过滤掉整个 URL 范围:
Replacing strings in cgi.query_string won't fix the problem, as the URL scope is populated at that point.
You can reference the value as a struct:
So combine that with structKeyExists:
Extending this further, you can filter out the entire URL scope:
您可以尝试
然后正常处理它..这样只有 html 实体被替换...
-sean
You might try a
Then just process it normally.. that way only the html entities get replaced...
-sean
可能有一种更干净的方法......但这似乎对我有用(语法假设 CF9):
There may be a cleaner way... but this seems to work for me (syntax assumes CF9):