After completing this
How-To you should be able to:
Use ESI tag ( <esi:choose>, <esi:when>,
<esi:otherwise>) for conditional branching.
Run the sample code to do the same using the instructions
provided.
Introduction
Edge Side Includes
(ESI) is XML based markup language used to define web page components
for dynamic assembly and delivery at the edge of the Internet. ESI compliant
Servers like OracleAS Web Cache caches and assembles partial pages defined
by the ESI tags. Perhaps the single most
powerful tool in any programming language is, the conditional branching
statement because it allows the flow of your program to proceed in
different ways according to the boolean test condition. ESI supports
conditional branching statements like <esi:choose>, <esi:when>,
<esi:otherwise> and these statements enables your program to
selectively execute different statements, based upon the test criteria.
This <esi:choose> block provides <esi:when> | <esi:otherwise>
statement set, comparable to if-else statement in some other
language like c/c++.
The following code snippet shows the template for <esi:choose>
block.
.....
<esi:choose>
<esi:when test="BOOLEAN-EXPRESSION1">
Do Something
</esi:when>
<esi:when
test="BOOLEAN-EXPRESSION2">
Do Something else
</esi:when>
<esi:otherwise>
If non of the test condition is passed
Do this
</esi:otherwise>
</esi:choose>
.....
Fig 1
Pre-Requisites for running the example
You will need the following
to run this example -
Oracle Application Server (9.0.3 or above).
This can be downloaded from here
Oracle9i JDeveloper (9.0.3 or
above). This can be downloaded from here.
This is optional and required only if you wish to deploy from
JDeveloper.
Description
The sample application has three types of customer
viz., Gold, Platinum and Normal customer. Based on the customer information
available, the application displays customized product information for
each type of the customer.
User selects one customer in the welcome page, welcome.html. When
the welcome page is submitted, customer type information is set and passed
to the display page, display.jsp. The display page, using the <esi:choose..>
tag, branches to the appropriate product pages, based on the customer
type. After the first request, all the product pages are cached in Web
Cache and branching happens within Web Cache without sending any request
to the origin server.
Code snippet
In welcome.html, user
can select any customer name, it could be of any type gold, platinum
or default. Gold and platinum type of customers are suffixed by _G and
_P respectively. The customer type selected will be stored in the variable named "customerType" and passed
to display page by using POST method. In display.jsp, the value of this
variable will be tested in the test condition and corresponding page will
be displayed. If the value of this variable
is gold, goldProductCatalog.jsp will be displayed else if the cookie value
is platinum, platinumProductCatalog.jsp will be displayed otherwise
othersProductCatalog.jsp will be displayed.
The following code snippet shows how to use <esi:choose>
to display different pages.
The complete source code for this sample is available
here.
This section discusses the instructions to run
the sample application
Step 1
Unjar
ConditionalBranching.jar using Winzip, or using the following
command:
> jar -xvf ConditionalBranching.jar
This creates a directory ConditionalBranching.
Step
2
If you are using JDeveloper then, follow these steps
Open Oracle9i JDeveloper and use 'File/Open' option
to select the ConditionalBranching.jpr from the ConditionalBranching directory.
Next, select Project/Make ConditionalBranching.jpr from
main menu.
Need to create an application server connection in case
if you dont have it.
Go to Connections -> Application Server
Connection. Right Click and 'click New connection'.
Enter connection name and select 'Oracle9i Application
Server'.
Enter user name and password
Enter Enterprise Manager's host name, port number and
Remote Application Server home directory (required only
if deployed on remote machine).
Click 'Next' and 'Test connection'. Click Finish button.
Now, Right clickConditionalBranching.deploy and select
Deploy to <connection name>, to the application server
connection, which you have created in the previous step.
Step
3
To deploy the
application using EM. follow the steps.
Go to EM web site -> default oc4j home.
Choose Deploy EAR file.
Enter J2EE Application name, Click the Browse button and
choose ConditionalBranching.ear from <SAMPLE_HOME>/deploy/ConditionalBranching.ear.
Enter the Application name as Personalize and click next.
Enter URL mapping as /HttpRequestVariable and click Finish.
Click Deploy to deploy the application.
Running the sample
Access the page on the browser, using the following
URL.