I have just started ColdFusion development and am getting stuck at creating a cfapplication that stores a variable, to use at a later date. All the tutor has provided us with is the following:
"Create your own 'Application.cfm' and save it in the root folder
alongside your 'hello world' examples."
i have this so far
<CFAPPLICATION
name=“mySite”
sessionmanagement=“yes”
clientmanagement=“yes”
setclientcookies=“yes”>
I want to add in a variable message that says "hello world". But I have no idea how to do it. I have been searching the net, but can't find any help. I am also getting the following message but have found no help on to resolve it:
"The value of the SESSIONMANAGEMENT attribute is invalid. The value
cannot be converted to a boolean because it is not a simple
value.Simple values are booleans, numbers, strings, and date-time
values."
If someone could help me with these that would be great, or if you can perhaps point me in the direction of some good ColdFusion tutorials that would be even better. As sadly there doesn't seam to be many decent ColdFusion tutorial's around that explain what's going on. Thanks for any help, it's much appreciated.
The syntax to set your variable is:
<cfset application.message = "Hello World">
Your error might be caused by the curly quotes in your code.
Related
there are many posts on issues similar to mine, but none of them has helped. Not sure what I am doing wrong. I am trying to load the jsoup jar using this.applicationSettings, and I keep getting an error. Specifically:
Application.cfc:
this.javaSettings = {
loadPaths = [ ".\lib" ],
loadColdFusionClassPath = true,
reloadOnChange= false
};
Yes, jsoup-1.11.2.jar is in \lib for that application. I tried \lib\ too; no joy.
But every time I try to use
myJsoup = createObject("java", "org.jsoup.Jsoup");
or
myJsoup = createObject("java", "org.jsoup.Jsoup").init();
I get an error,
cannot load class through its string name, because no definition for the class with the specified name [org.jsoup.Jsoup] could be found
Does not matter what function I place the init code in -- handler or model -- or if I put it in a cfscript or cfset. I can even put it in index.cfm and still get the same error. Does not matter what I restart or how many times I restart it. It is as if ColdBox and/or Lucee just refuses to acknowledge the existence of the jar file or something. What gives?
I sure would appreciate any tips! Thanks in advance!
I'm not sure if this is just bad documentation out in the wild, a shortcoming of my own understanding or simply a bug in ColdFusion and Lucee...
I put together a simple test and recreated what you're seeing in both engines. I originally figured there must be an issue with paths in Lucee but ACF produces the same error.
Looking at existing code I use, it seems I always populate the full path to the JAR/Class files.
I often do something like this (which works) to load everything in the /lib directory:
this.javaSettings.loadPaths = directoryList(expandPath("/lib"));
Which in turn sets the value to [ "/mypath/lib/jsoup-1.11.2.jar" ].
Thanks for everyone in advance.
I encountered a problem when using Scrapy on Python 2.7.
The webpage I tried to crawl is a discussion board for Chinese stock market.
When I tried to get the first number "42177" just under the banner of this page (the number you see on that webpage may not be the number you see in the picture shown here, because it represents the number of times this article has been read and is updated realtime...), I always get an empty content. I am aware that this might be the dynamic content issue, but yet don't have a clue how to crawl it properly.
The code I used is:
item["read"] = info.xpath("div[#id='zwmbti']/div[#id='zwmbtilr']/span[#class='tc1']/text()").extract()
I think the xpath is set correctly and I have checked the return value of this response and it indeed told me that there is nothing under this directory. Results shown here:'read': [u'<div id="zwmbtilr"></div>']
If it has something, there should be something between <div id="zwmbtilr"> and </div>.
Really appreciated if you guys share any thoughts on this!
I just opened your link in Firefox with NoScript enabled. There nothing inside the <div #id='zwmbtilr'></div>. If I enable the javascripts, I can see the content you want. So, as you already new, it is a dynamic content issue.
Your first option is try to identify the request generated by javascript. If you can do that, you can send the same request from scrapy. If you can't do it, the next option is usually to use some package with javascript/browser emulation or someting like that. Something like ScrapyJS or Scrapy + Selenium.
So I have a cfscript tag that runs some XML data through but I'm getting an error on one of my executes its getting weird data it cant use, I am trying to find out what this data is however, all of my attempts to cfdump this data have failed miserably. Does anyone know of a way to get a data log from inside cfscript data?
I've tried:
-Ending the script writing the dump and restarting the script
-ending the script writing the dump and aborting
-putting the dump at the end of the cfscript
I'm running out of ideas. Thank you ahead of time!
Here's are my tips:
First, create a UDF in tag format - I call my "sdump":
<cfunction name="sdump">
<cfargument name="anyvar" required="true"/>
<cfdump var="#anyvar#"/>
</cffunction>
Then in your cfscript while debugging you can simply do:
<cfscript>
sdump(myProblemobject);
</cfscript>
That keeps you from having to break your script block all the time. I actually include mine in a CFC library of functions that's loaded in Onrequest.
Second, sometimes cfdump doesn't play nice with complex XML. It's gotten really smart in CF 9 and later, but I remember CF8 not always loving complicated XML. In that case you have to use your noggin.
For example, try using toString() on the XML object itself and dumping it in source as in tmpvar = toString(myXml); This is more useful if you split out the specific node that is causing you problems into it's own little xml object. Then use dump or (if dump fails) try "writeoutput();" - which is made like a cfoutput for cfscript - like so:
<cfscript>
xmlTmp = toString(myXml);
writeoutput(xmlTmp);
</cfscript>
Working your way through the xml attribute by attribute and node by node might be tediuous, but it might be easier than walking your eyballs through the raw XML looking for issues.
Remember too that you can validate your XML document or var using the various isXML() functions native to CF (isXML(), isXMLAttribute() etc.). Not sure what the list looked like in CF8. Good luck - these sort of problems are always trial and error I'm afraid. :)
I want to do something in ColdFusion that is similar to sprintf in C or Perl. I found this
answer, which seems to be what I'm looking for. However, I can't get it to work.
Here is what I'm trying:
<cftry>
<cfset firstName="John">
<cfset output=createObject("java","java.lang.String").format("Hello, %s!", firstName)>
<cfcatch type="any">
<cfdump var="#cfcatch#" expand="false">
</cfcatch>
<cftry>
And here is what I get:
cfcatch.Message: The format method was not found.
cfcatch.Detail: Either there are no methods with the specified method
name and argument types or the format method is overloaded with
argument types that ColdFusion cannot decipher reliably. ColdFusion
found 0 methods that match the provided arguments. If this is a Java
object and you verified that the method exists, use the javacast
function to reduce ambiguity.
This is an overloaded method, so I did as suggested and used JavaCast on the arguments:
<cfset output=createObject("java","java.lang.String").format(JavaCast('string', "Hello, %s!"), firstName)>
<cfset output=createObject("java","java.lang.String").format("Hello, %s!", JavaCast('string', firstName))>
<cfset output=createObject("java","java.lang.String").format(JavaCast('string', "Hello, %s!"), JavaCast('string', firstName))>
and got the same error every time.
I tried another static method on the String class, valueOf, and it worked fine.
Edit:
I've already seen a comment, and I'm not sure how to respond to those, but maybe I should explain here. What I've shown above is an extremely simplified example of what I am trying to do. The goal is to use a format string to provide lots of formatting in one place, and then simply pass in a list of variables, instead of formatting a bunch of variables and outputting them, or formatting them as I'm outputting them. With the format method, I plan to build a set of format strings that match the output I need, then I will just cfloop or cfoutput over a query, run this one method inside, and get the output I want. No DateFormat, NumberFormat, Left, Right, etc. If I can't get this working, that is plan B though.
I'm running ColdFusion 9.01, Windows 7, Java 1.6.0_22.
Any and all help is greatly appreciated.
Answer based on my comment above:
It probably can't match the format method you're looking for because its signature is format(String, Object[]) and your second String argument can't be automatically converted to an Object array.
You could change the argument to encapsulate the name in an array as follows: format("Hello, %s!", [firstName]).
Thanks to Leigh for being so courteous, I upvoted your comments :)
This code:
<cfimage action="info" structName="imageInfo" source="#imagePath#">
is giving this error:
The attribute 'structName' is required for the tag. (Found:
[source, structname, action])
When I run this code in CFBuilder - everything is OK, but I must use CFEclipse.
What should I do (I use CF9)?
Thank you for your answers!
Of course this problem won't prevent you from running your application on ColdFusion. It is just an IDE warning that something is wrong.
You have a few options.
Try using a lowercase N in structName. i.e. structname. ColdFusion is not case-sensitive, but Java is, and CFEclipse is a Java application.
If that does not work, then it probably means that the dictionary file that drives the code assist is not correct. You can go earch forthose XML files and update them to include that attribute.
You can use CFBuilder. I know you said you can't, but I have to question why. You know there is a free version that is just as good as CFEclipse, right?
The problem is that there's a casing glitch in that file Peter mentions. There's one reference to "structName" to define the attribute itself, and another "structname" which is in the list defining which attributes are needed for action="info". If you make them both the same, then restart Eclipse, you should be OK (that's I've needed to do to make the error indicator go away).