How to use <esi:environment> tag

OracleAS Web Cache How-to

Date: November 28, 2003

How to use <esi:environment> tag to include custom environment variables

After completing this How-To you should be able to:
  •   Use <esi:environment> tag to include custom environment variables

ESI is an open specification for assembling dynamic pages on the edge of the network. ESI is an XML based markup language. It enables dynamic content assembly of fragments by ESI compliant servers like OracleAS Web Cache.

ESI supports HTTP request variables and custom environment variables to be used within esi tags. Some of the HTTP request variables include $(HTTP_COOKIE{username}), $(QUERY_STRING{searchstring}), $(HTTP_HOST). These variables can be used in the esi tags. For example,

<esi:include src="http://xyz.com/welcome.jsp?user=${HTTP_COOKIE{username})">

ESI also supports inclusion of custom environment variables. The custom environment variables are defined in the XML. For example,.

<?xml version="1.0"?>
<esi-environment esiversion="ORAESI/9.0.4">
   <bahamas>6</bahamas>
   <bermuda>1</bermuda>
   <caribbean>2</caribbean>
   <hawaii>2</hawaii>
   <lasvegas>1</lasvegas>
   <mexico>3</mexico>
</esi-environment>

These included variables can be used within esi tags just like the HTTP request variables.

The opinion poll sample application accepts opinion from the users and displays poll results. The poll results page retrieves poll results as XML from the servlet and it is included in the page as custom environment variables. Following code snippet shows how to include custom environment variables.

.....
<esi:environment src="/technology/esienvironment/pollresults" name="pollresults"/>
.....
<tr class="contenttext">
<td align="left" bgcolor="#FFFFFF">Bahamas</td>
<td align="left" bgcolor="#FFFFFF"><esi:vars>$(pollresults{bahamas})</esi:vars></td>
</tr>
<tr class="tabledata">
<td align="left">Bermuda</td>
<td align="left">
<esi:vars>$(pollresults{bermuda})</esi:vars></td>
</tr>
....

The time stamp in the poll results page, shows the time, when the page was cached. The dynamic data, poll results alone is refreshed for every request using the <esi:environment> tag.

Pre-requisites for running the example

You will need the following to run this example -

  • Oracle Application Server (10g or above). This can be downloaded from here
  • Oracle 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.

Deploying the Sample

The complete source code for this sample is available here. This section discusses the instruction to run the sample application

Step 1 Unjar esienvironment.jar using Winzip, or using the following command:

> jar xvf esienvironment.jar

This creates a directory esienvironment.

Step 2

If you are using JDeveloper then, follow these steps

  • Open Oracle9i JDeveloper and use File/Open option to select the esienvironment.jws from the esienvironment directory.
  • Next, select Project/Make esienvironment.jpr from main menu.
  • Create an application server connection
    • Go to Connections -> Application Server Connection. Right Click and click New connection..
    • In step 1, enter connection name and select Oracle9i Application Server
    • In step 2, enter user name and password
    • In step 3, enter Enterprise Manager's host name, port number and Remote Oracle AS home directory(required only if deployed on remote machine).
    • In step 4, click Next and Test the connection. Click Finish button.
  • Now, Right click esienvironment.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 esienvironment.ear from <SAMPLE_HOME>/deploy/esienvironment.ear
  • Enter the Application name as esienvironment and click next
  • Enter URL mapping as /esienvironment and click Finish
  • Click Deploy to deploy the application.

Running the Sample

Access the page on the browser, using the following URL

http://<host_name>:<port>/esienvironment/poll.jsp

where, <host_name> is the machine on which Web Cache is installed and <port> is the port on which Web Cache listener is running.

For Example, http://incq185b.idc.oracle.com:7777/esienvironment/poll.jsp

Resources


Please enter your comments about this sample in the OTN Sample Code Discussion Forum.



E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy