21.What is difference between Application.cfm and Application.cfc?
application.cfc gives you more control over when code runs.
In an application.cfm file, all of the code in that file is processed at the start of every page request.
With application.cfc we will write code in different methods which will get fired on specific events
22.What if we have both Application.cfc and Application.cfm present in the same folder?
Application.cfc will be given more priority, Application.cfm will be ignored if the ColdFusion version is ColdFusion MX 7 +.
If it is any version less that ColdFusion MX 7 then Application.cfm will be given more priority Application.cfc will be ignored because application.cfc was introduced in CF7.
23.What is look up order for Application.cfc/Application.cfm in coldfusion?
We can set the order in which ColdFusion searches for Application.cfm or Application.cfc if it is not found in the current project folder.
We can set ColdFusion to search as follows:
- default search order:ColdFusion looks for an Application.cfc/Application.cfm file from the current folder until the system root directory. On Windows, this could be C:\ and on UNIX, /opt.
- till web root:ColdFusion looks for an Application.cfc/Application.cfm file from the current folder till web root.
- in web root:ColdFusion looks for an Application.cfc/Application.cfm file in the current folder or web root.
24.What does CFC mean? How it is different from CFM page?
Cfc is more organized and tidy way of writing the coldfusion code.
Consider if we we writer few function udfs inside the cfm file then all that functions will get executed everytime we load the page ColdFusion components (otherwise known as CFCs) are a powerful feature of ColdFusion MX that allows developers to introduce object oriented programming techniques into their ColdFusion skillset.
A ColdFusion component is basically a collection of functions that relate to a given entity, like for example, a Customer. You could create a ColdFusion Component that is responsible for the programming logic regarding your customer records.
For example, you could create one ColdFusion component called customer.cfc that contains five functions to perform database queries. One could create a new customer record, another function could update customer records, another to retrieve, one for deleting, and one for listing your customers.
Other functions could be included too.
By doing this, you would have all your programming logic for customers in one place, which has got to be a good thing - you're effectively separating your presentation from your logic.
OK, so you're thinking, "I could have done that using a CFINCLUDE tag!". True, however, ColdFusion components are much more powerful than the CFINCLUDE tag.
25.What are the benefits of using ColdFusion Components?
- Security: You can restrict access to a ColdFusion component and it's function
- Performance: ColdFusion Components are faster. This is because they are compiled. Note that a ColdFusion component only has to be compilied the first time it is called. It will then be pre-compiled for all subesquent calls unless you update the component, in which case it will compile once again.
- Extensibility: ColdFusion components can share methods with other ColdFusion components. You can also make them available to applications built in other languages by using SOAP or URL calls.
- Reusability: You can code your component so that it is a "black box" in that you can move it around without anything breaking - it's a standalone piece of code that accepts input and provides output. Also, generally, once you've called a component in a page, you can reuse it without having to call it again in that page.
- Documentation: ColdFusion Components are self documenting - they generate their own comments. This is based on the developer using the "Hint" attribute.
26.What are the different ways to invoke CFC?
Method 1: <cfinvoke>
<cfinvoke component="user" method="Get" returnvariable="usr">
<cfinvokeargument name="id" value="#id#">
</cfinvoke>
Method 2:
<cfobject component="user" name="userObj">
<cfinvoke component="#userObj#" method="Get" id="#id#" returnvariable="usr">
Method 3:
<cfscript>
userObj=CreateObject("component", "user");
user_id=userObj.Get(id);
</cfscript>
Method 4: URL Invocation
When invoking CFCs via URLs, the method and any arguments are passed as URL parameters, as seen here:
27.What are the keywords or ways to impelement inheritance in the coldfsuion?
Extends attributes is used in coldfusion components to implements inheritance.
The Super keyword supports only one level of inheritance. If you use multiple levels of inheritance, you can only use the Super keyword to access the current component's immediate parent.
28.What is custom tag in coldfusion?
CFML allows language extensions in the form of custom tags, which are tags created by the developer that are not part of the CFML language itself.
Custom tags are regular CFML files which are intended to be invoked as tags, although it is possible to treat a template as both a custom tag and a regular template.
Custom tags are written in CFML and are typically invoked by prefixing the custom tag's file name with cf_, although there are other ways to invoke custom tags.
If a template is invoked as a custom tag, the attributes used to invoke that tag are available within the tag in an attributes scope and the variables for the calling page are accessible via the caller scope.
For example, if writing a custom tag to perform addition, taking two attributes and adding them together, the tag would be an addition.cfm file which could look like this:
<cfset caller.addition = attributes.first + attributes.second />
Assuming the tag is in the same directory as the file or in a pre-defined customtags directory, it can be invoked thus:
<cf_addition first="1" second="2">
Custom tags can also be invoked by the CFMODULE as follows-
<cfmodule first=”1” second=”2” template=”addition.cfm”>
29.What are CFX tags?
CFX tags are custom tags which are developed using Java or C++, and are prefixed with cfx_ just like cf_. Java and C++ tags are added to the CFML runtime environment using the CFML engine's administrator or by editing configuration files.
30.What is use of cfmodule tag?
Invokes a custom tag for use in ColdFusion application pages.
Module.cfm
<cfsettempName = "Datta">
<cfmoduletemplate="test.cfm"
firstname="dattatray"
lastname="shinde">
Following cfm file will explain, how to call/use variables in caller file and passed parameters-
Test.cfm
<cfdumpvar="#caller.testName#">
<cfdumpvar="#attributes.firstName#">
If we have to use cfmodule tag with name=”test” parameter as follows then we need to keep test.cfm in C:\ColdFusion11\cfusion\CustomTags
<cfmodulename="test"
firstname="dattatray"
lastname="shinde">
31.What is Session scope?
A session refers to all the connections that a single client might make to a server in the course of viewing any pages associated with a given application. Sessions are specific to both the individual user and the application. As a result, every user of an application has a separate session and has access to a separate set of session variables.
This logical view of a session begins with the first connection to an application by a client and ends after that client's last connection. However, because of the stateless nature of the web, it is not always possible to define a precise point at which a session ends. A session should end when the user finishes using an application. In most cases, however, a web application has no way of knowing if a user has finished or is just lingering over a page.
Therefore, sessions always terminate after a time-out period of inactivity. If the user does not access a page of the application within this time-out period, ColdFusion interprets this as the end of the session and clears any variables associated with that session.
The default time-out for session variables is 20 minutes. You can change the default time-out on the Memory Variables page in the Server Settings area in the ColdFusion Administrator. It is also possible to define session timeout time in Application.cfm or Application.cfc.
To uniquely identify user sessions CFID and CFTOKEN which are session variables will be used. Since some cases user might disable cookie, JSESSIONID can also be used to track sessions in coldfusion.
32.What is client scope?
Client variables in coldfusion allows us to store user information and preference over the multiple session. Default timeout as known as purge interval for the client variables is 1 hr and 7 minits and cannot be less than 30 minuts.
33.What is Application Scope?
Application variables are available to all pages within an application, that is, pages that have the same application name. Because they are persistent, you can pass values between pages with a minimum of effort.
Unlike Client and Session variables, Application variables do not require that a client name (client ID) is associated with them. Thus, they are available to any clients that specify the same application name. Also, you do not need to use the cfapplication tag to enable Application variables.
Using the ColdFusion Administrator you can enable or disable Application variables in all applications; you cannot override this setting for an individual application.
ColdFusion stores Application variables in the ColdFusion Server's memory and you can set timeout values for these variables either with cfapplication, or by specifying timeouts in the ColdFusion Administrator.
34.What is server Scope?
Server variables are associated with a single ColdFusion server. They are available to all applications that run on the server. Use server variables for data that must be accessed across clients and applications, such as global server hit counts.
Server variables do not time out, but they are lost when the server shuts down. We can delete server variables.
Server variables are stored on a single server. As a result, we should not use server variables if you use ColdFusion on a server cluster.
We access and manipulate server variables the same way use Session and application variables, except we use the variable prefix Server.
Server.ColdFusion.AppServer | The name of the J2EE application server ColdFusion is using. For ColdFusion server editions, which have an integrated application server, the name is JRun4. |
Server.ColdFusion.Expiration | The date on which the ColdFusion license expires if it is the trial version. |
Server.ColdFusion.ProductLevel | The server product level, such as Enterprise. |
Server.ColdFusion.ProductName | The name of the product (ColdFusion). |
Server.ColdFusion.ProductVersion | The version number for the server that is running, such as 6,0,0. |
Server.ColdFusion.Rootdir | Directory under which ColdFusion is installed, such as C:\cfusion. |
Server.ColdFusion.SerialNumber | The serial number assigned to this server installation. |
Server.ColdFusion.SupportedLocales | The locales, such as English (US) and Spanish (Standard), supported by the server. |
Server.OS.AdditionalInformation | Additional information provided by the operating system, such as the Service Pack number. |
Server.OS.arch | The processor architecture, such as x86 for Intel Pentium processors. |
Server.OS.BuildNumber | The specific operating system build, such as 1381 |
Server.OS.Name | The name of the operating system, such as Windows NT. |
Server.OS.Version | The version number of the operating system, such as 4.0. |
35.What are the differences between Client and Session Scope variables?
You can’t store complex structures inside the client variable but session can store complex structures.
Client variable by default will get stored in the registry but we can also store in database or in cookie. Session and Application variables will get stored in coldfusion server’s memory.
36.What are the default timeouts for the application and session variables?
Application – 2 days, Session- 20 mins
Application and session scopes are independent of each other. Application variables expire when you restart the ColdFusion server.
Session variables expire when the user's session ends. Both types of variables also expire after a time-out period that you specify on CFADMIN page or in the cfapplication tag.
- Server variables – tied to CF Server and Accessible by all clients and applications on a single Server
- Application variables - Tied to a single application and accessible by multiple clients
- Client variables - Tied to a single client and accessible over multiple sessions
- Session variables – Tied to single user session and Exist for one client or browser during a single session
37.Can you delete all the session variables?
NO, The Session Client scope has four built-in, read-only variables –CFID, CFTOKEN, URLTOKEN, SESSIONID.
38.What are different types of errors in coldfusion?
There are three types of ColdFusion Errors:
- Exception: Where the error stops the request from completing its process.
For example-
variable is not defined and used somewhere inside code
- Missing Template: When an HTTP request for a page cannot be found.
For example-
xyz.cfm used below doesnot exists.
<cfincludetemplate="xyz.cfm">
- Form Field Data Validation: When server side form validation fails.
For example-
credit card no validation as below.
<cfinputvalidate="creditcard"name="credit_card"id="credit_card"value="">
39.What are different ways to handle errors in coldfusion?
When an error is thrown, it will bubble up the application until the first Error Handler catches it. The order in which the handlers will be called is:
- CFCATCH
- CFERROR in Application.cfm OR onError() in Application.cfc
- Site-Wide error handling
- Coldfusion error handler
40.How to create and consume web service in coldfusion? SOAP based?
To Create a webservice in coldfusion all we need to do is create cfc first and write a function having acess as “remote”. That’s it.Coldfusion will automatically create a WSDL file for this webservice which can be viewed through browser (localhost:8500/Coldfusion/webservice/User.cfc?wsdl) or through coldfusion administrator (Data Services web services)
<!--- User.cfc --->
<cfcomponentoutput="false">
<cffunction access="remote" name="display_user" returntype="string">
<cfargument name="user" type="string">
<cfreturn "Hello" & ' ' & user>
</cffunction>
</cfcomponent>
The above created web service can be consumed in coldfusion as follow –
<!--- display_user.cfm --->
<cfinvoke webservice="http://localhost:8500/coldfusion/webservice/user.cfc?wsdl"
method="display_user"
returnvariable="return_message" >
<cfinvokeargument name="user" value="dattatray">
</cfinvoke>
<cfoutput>
#return_message#
</cfoutput>
|