How to use the getPageContext().forward() function with ColdFusion MX
Issue
Improper use of the getPageContext().forward() function with ColdFusion MX may result in "java.lang.outOfMemoryError" or similar errors.
Reason
By definition, getPageContext().forward() is the same function in JSP as described at http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/jsp/PageContext.html#forward(java.lang.String).
Note the following remark from the above techdoc:
"Once this method has been called successfully, it is illegal for the calling Thread to attempt to modify the ServletResponse object. Any such attempt to do so, shall result in undefined behavior. Typically, callers immediately return from _jspService(...) after calling this method."
For ColdFusion users, this means it is illegal to generate any additional output after calling getPageContext().forward().
Solution
Be sure there is no output on the page after the getPageContext().forward() function.
The use of cfabort after the getPageContext().forward() function will force this behavior.
Example:
<cfif isdefined("form.submit")> <cfset newURL = "helloworld.cfm"> <cfset GetPageContext().Forward( newURL ) /> <cfabort> </cfif> <cfform method="post"> Test getPageContext().forward() <input name="submit" type="submit" value="GO" /> </cfform>
Additional Information
http://livedocs.adobe.com/coldfusion/7/htmldocs/00000490.htm
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
