How can I tell when I am in the request scope and/or the response scope.

mfreeman2
mfreeman2 used Ask the Experts™
on
Hello,

I am maintaining a coldfusion application that was developed by another developer.
In the code are references to items in the request scope e.g. <cfset request.datasource="DataSourceName"> or <cfset request.VariableName="DataValue">I understand that these are variables defined in the request scope but I am not sure that I understand the "scope" (if you will) of the request scope. That is, for variables defined in the request scope, when/where are they accessible. Is it before a page is sent to the server, after a page returns from the server, both, or it doesn't matter?

Same question for response. For example there is a response scope in (in believe) classic ASP that allows you to code "response.write("data_to_write"). At what time is a web page in the response scope.

Also, if you are familiar with a good source of information on this subject I would appreciate a reference to it, although this third part of the question is not necessary to be awarded the points.

Thanks much,

Mfreeman2
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Well, I don't have the ColdFusion lingo down ... but ... it's been almost 3 hours and nobody's come up w/ a better answer.

REQUEST -- this is information about what the browser sends to the server.  The browser sends a request for a particular page, along (possibly) with a cookie, GET variables, POST variables, and other header stuff telling about the browser's capabilities.

RESPONSE -- this is information the server sends back to the browser.  It usually includes the HTML that the browser will render.  Hence classic ASP does Response.Write("data to write") as what it sends back. It can include a cookie to place ... not sure what else it might include.

Does that help some?
well If you looking after Scope so hre is my answer:

ColdFusion supports a number of different variable scopes, where scope refers to the context in which the variable exists within an application. The scope encompasses where the variable came from (such as a form field, a URL, etc.), how it can be used, and how long it persists. As we'll discuss shortly, when you refer to a variable in your code, you can use just the variable's simple name (MyVar) or its fully scoped name (scope.MyVar). The variable scopes available in ColdFusion are: LOCAL,FORM,URL,QUERY,FILE,CGI.

the Request Scope is avaliable to the complete Application, it is accessible everywhere. Just you need to append it to value as:

<cfset request.abc = "1">

Now request.abc is avaliable to all pages whereever you use it.

Request
Request variables offer a way to store data in a structure that can be passed to nested custom tags. Because variables in the request scope are available to all templates in a request, they are often set in an application's Application.cfm template and used in lieu of application variables. Request variables must always be referenced using the request prefix as in request.variable_name.

The Response.write Just works like cfoutput tag in Coldfusion. So whenever you would like to show something on screen u use cfoutput.

Tag

I hope i had made all things clear, if something remains let me know

Cheers

Most Valuable Expert 2015
Commented:
> That is, for variables defined in the request scope, when/where are they accessible. Is it before
> a page is sent to the server, after a page returns from the server, both, or it doesn't matter?

None of the above really.  The REQUEST is available just about anywhere _while_ a requested page is being processed _on_ the CF server.  For example, UserA requests page  http://www.yourserver.com/getCustomerList.cfm.  While the CF code for that page is executing on server, the REQUEST scope is available.  If the "getCustomerList.cfm" page calls other pages, custom tags, or CFC's, the REQUEST is available to all of them as well.  Once the server is done generating the "getCustomerList.cfm" page, obviously the communication between browser and server ends. So the REQUEST scope is no longer available.  

> (in believe) classic ASP that allows you to code "response.write("data_to_write"). At what time is a web
> page in the response scope.

CF is a bit different. Unless you've explicitly disabled output, any time you print or output something to the screen it is written directly to the RESPONSE stream.  You don't need a special call to response.write().  You have implicit access to it just about everywhere.  Again, unless you've disabled it using tags like <cfsilent>, etc...

An example is , say you have a simple cfm page, with NO cf code whatsoever.  Just  some html:

     <strong>Today</strong> is Monday.  

That text is written directly to the RESPONSE stream.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial