Accessibility
 
Home > Products > UltraDev > Support > Building Common Applications
Dreamweaver UltraDev Icon Macromedia Dreamweaver UltraDev Support Center - Building Common Applications
Testing the code

As the page stands, you have no way of knowing whether or not a recordset is created only once during the session. There could be a flaw in your code that causes a recordset to be created every time the page runs—a behavior you don't want—and you wouldn't know about it by looking at the source code in a Web browser.

You decide to check this by adding code that signals the creation of a recordset and tells you about it on the page.

In the code near the top of the page, you declare and initialize a boolean variable called rs_created:

<% boolean rs_created = false; %>

Boolean variables contain the values true or false. The value of rs_created starts as false because no recordset has been created yet.

In the conditional code block, you add the following scriptlet immediately following the code generating the recordset:

<% rs_created = true; %>

The value of the variable changes to true only if the conditional code block is executed—that is, if a recordset has been created. Otherwise, the value of the rs_created variable remains false.

Next, you display the results on the page. In an unobtrusive place in your page layout, you add the following code:

<% if (rs_created == true)
	out.print("A recordset was created.");
else
	out.print("No recordset was created."); %>

Note: For developers familiar with the Java programming language, the out object is an implicit object in JSP. As such, you don't need to import a class or package, or instantiate it.

You run the page a few times to make sure the recordset is not created every time. The first time, the sentence "A recordset was created." is displayed on the page in a browser. After that, only the sentence "No recordset was created." appears. The test confirms that the recordset is not created every time and that the code is working as expected. Satisfied, you delete the test code from the page.

To Table of Contents Back to Previous document Forward to next document