360 users using DBSP now!
home -> documentation -> environment guide -> Passing variables between DBSP pages

There are various ways to pass variables or values across DBSP pages:

Passing variables directly in the URL (query fields)

The most direct method to pass variables between DBSP pages is to do it across the http URL (Uniform Resource Locator). The URL syntax is described below:

"http:" "//" host [":" port ] [abs_path [ "?" query] ]

For example, consider the next URL address:

http://www.dbsptech.com/support?country=mx&userid=299EFXJS293

host References the Internet host who will be requested. In the example, this value corresponds to "www.dbsptech.com"
port This optional variable indicates the port number in which the web server is listening. If omitted, the value 80 is considered by default. This is the case of the example.
abs_path Determines the path on the host machine where the target of the request is found. In the example, it corresponds to the value "/support"
query This is the section used for passing variables. Each variable takes the form name=value. Multiple variables could be sent separated by the ampersand character. In the previous example, this value corresponds to "country=mx&userid=299EFXJS293".

Hypothetically, there is no limitation over the size of the URL, as you can see in the HTTP 1.1 specification RFC-2616, section 3.2.1.

Note: Its very easy to confuse the & character with the ? character while we are really trying to separate the query fields. Remember that the query fields separation character is the ? (just one), and after that all fields are separated by the & character.

 

Passing variables using a form (content fields)

Another way to pass variables between dbsp pages is using a post operation in some HTML form. With this method, all the controls included inside the form will send their values to the next page with the structure "Control=Value".

For example, consider the next code snippet:

<form name="MyForm" method="post" action="page2.dbsp">

Control 1: <input type="text" name="control1" value="one">

Control 2: <input type="text" name="control2" value="two">

<button type="submit">Send</button>

</form>

This page will display something like this:

Control 1: Control 2:

Now, when the Send button is pressed, the values contained in each control will be available in the next page (in this case page2.dbsp, as specified on the action property):

Control1=one
Control2=two

This feature could be used in several ways, but the main application is for insert or edit values into a database table, as we shall see in the next chapter.

 

Scope of variables

Whether we use the first or the second method listed above, we only make the variables available for the next page and only for next page. This means that the existence of the variables is limited to the next requested page and nothing more. This is convenient in the sense that we don't want to store in memory every form value or variable used in each page of the web site. However, if we want to store in memory values for more than the next page, we have another specific method for this purpose, described in the next section.

 

Operative Examples

Example 5.1

This example shows how to pass some variables between two pages as part as the URL.

Source code
Test example



Example 5.2

This example shows how send information contained in a form.

Source code
Test example

Previous | Next