The most part of dynamic web applications needs to display its content according to the user input or user profile. In some cases, it is difficult to concentrate all the possible options in one single page leading to applications that are difficult to maintain and modify. In this case, is preferable to divide all the possible options in different pages and display the correct one.
The REDIRECT tag
The REDIRECT tag allows you to change the flow of the application by jumping to a different page at runtime. This jump or redirection has two modalities:
Unconditional redirection
A redirection of this type will be executed as soon the program flow reaches the REDIRECT tag. The syntax is described below:
|
<#REDIRECT DOC="document"/>
|
In this case, the program will jump to the page specified in the DOCproperty as soon as the interpreter reaches this point.
Conditional redirection
This type of redirection is conditioned to the result of a Boolean expression. The general syntax of this kind of redirection is described below:
|
<#REDIRECT EXPRESSION="anexpression" DOC="document"/>
|
In this case, if the expression evaluates to true, the redirection will be executed. If it evaluates to false, the redirection will be discarded and the REDIRECT tag code removed.
|
Note: In both cases, all the interpreted code accumulated before the REDIRECT tag will be discarded and substituted by the content located in the new page. However, all the database modifications made with the DATASET or QRYEXEC tag before the redirection will not be discarded (in the database context, will not be rolled back).
|
Examples
Example 1. A simple redirection
This example shows an unconditional redirection.
Source code
File: examples/Ex7_5_1.dbsp
<h1>Unconditional redirection</h1> <p>All this code will be ignored and the redirection page will be displayed instead.</p> <p>However, any modification to the database made here using the DATASET or QRYEXEC tag will be executed.</p> <#REDIRECT DOC="Ex7_5_1a.dbsp"/>
|
File: examples/Ex7_5_1a.dbsp
<html> <body> <h1>A simple redirection</h1> <hr> <p>This page has been redirected.</p> </body> </html>
|
Test example
Example 2. Conditional redirection.
In this example, the application displays the correct page according the user profile.
Source code
File: examples/Ex7_5_2.dbsp
<html> <body> <h1>Conditional redirection</h1> <hr> <p>Select your user profile:</p> <form name="frmProfile" method="post" action="Ex7_5_2a.dbsp"> <input type="radio" name="Profile" value="adm">Administrator<br> <input type="radio" name="Profile" value="usr">Normal user<br><br> <button type="submit">Select</button> </form> </body> </html>
|
File: examples/Ex7_5_2a.dbsp
<html> <#REDIRECT EXPRESSION="profile='adm'" DOC="Ex7_5_2b.dbsp"/> <body> <h1>User profile</h1> <hr> <p>The normal user profile was selected.</p> <p><button onclick="javascript:history.back()">Back</button></p> </body> </html>
|
Test example
Previous | Next
|