OracleAS Web Cache How-to

Date: September 12, 2003

How to use <jesi:personalize> tag for page personalization

After completing this How-To you should be able to:
  •   Use <jesi:personalize> tag to customize your page by substituting the cookie values before serving the cached page.
  •   Run the sample code to do the same using the instructions provided.

Introduction

The main purpose of cookies is to identify users and possibly prepare customized web pages for them. When you enter a web site using cookies, you may be asked to fill out a form providing such information as your name and interests. This information is packaged into a cookie and sent to your web browser which stores it for later use. The next time you go to the same web site, your browser will send the cookie to the Web server. The server can use this information to present you with custom web pages. So, for example, instead of seeing just a generic welcome page you might see a welcome page with your name on it.

Let us now move one step ahead towards reducing processing overhead on the origin server, and enhancing its capability and availability by caching the dynamic content using OracleAS Web Cache. Web Cache acts as a content aware server accelerator and tries to reduce the load on busy web servers by storing frequently accessed page in memory, eliminating the need to repeatedly process the request for those pages on the mid-tier servers

In the web pages, where the dynamic content is generated using the cookie values, these pages can be cached using the <jesi:personalize> tag. The personalize tag inserts personalized content from the cookie in its place holder of the page. This processing is done by the ESI processor built within the Web Cache.The first browser request to the page is sent to the origin server. Web Cache caches this page based on the cache policy set on the page. Succeeding requests to the pages are handled at Web Cache itself. ESI processor substitutes the cookie values in the cached page and the request are sent to the origin server.

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
  • 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.

Description

This sample application has two web pages viz, welcome.html and the display.jsp. Users enter their information like title, first name and last name in the first page, welcome.html. This page stores the user information in the cookie and sent the request to the second page, display.jsp. This page is a dynamic web page, which retrieves values stored in the cookie and displays it. With out any cache server like OracleAS Web Cache, this page will be generated for every request. Using the <jesi:personalize> tag these requests are handled at Web Cache itself. ESI Processor retrieves the user information stored in the cookies and substitutes them in the dynamic page cached in the cache server. The dynamic content is requested only once and served multiple times by the cache server. This can be visualized by the time stamp generated in the dynamic page.

Code Snippet

Here is the code which will insert an ESI placeholder with the cookie name and value in the response body.
   


  1. .....
  2. <tr class="tabledata">
  3.   <td>Welcome: </td>
  4.   <td align="left">
  5.     <jesi:personalize name="title"/>
  6.     <jesi:personalize name="firstname"/>
  7.     <jesi:personalize name="lastname"/>    
  8.   </td>
  9. </tr>   
  10. .....
                                                                                                              Fig1


As shown in Fig1, <jesi:personalize> tag is used to display the user name by using the cookie variable,  if the cookies( title, firstname, lastname) are found in the request and has a non-null value, its value will be substituted in the page. JESI tag library converts these tags into ESI tags as shown in Fig 2.



  1. .....
  2. <tr class="tabledata">
  3.   <td>Welcome: </td>
  4.   <td align="left">
  5.     <ESI:VARS>$(HTTP_COOKIE{"title"}</ESI:VARS> 
  6.     <ESI:VARS>$(HTTP_COOKIE{"firstname"}</ESI:VARS>
  7.     <ESI:VARS>$(HTTP_COOKIE{"lastname"}</ESI:VARS>
  8.   </td>
  9. </tr>   
  10. ......
                                                                                                              Fig2


After this ESI processor will try to retrieve the value of all these cookies( title, firstname, lastname) and try to replace them by there value in ESI processor without sending the request back to the origin server.

In our example we are displaying time stamp also in display.jsp page and this whole page is cached by using <jesi:control> tag for 60 seconds so if any other user enter his name in welcome.jsp and submit before the page expiration time, he will also see the same time stamp along with with his name and after 60 seconds the cached page (display.jsp) gets expired and he will see different time in the screen along with his name. This is how <jesi:personalize> tag can be used to customize page for different users while share same cached information among different users.

Deploying the Sample

The complete source code for this sample is available here

This section discusses the instructions to run the sample application

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

> jar -xvf Personalize.jar

This creates a directory Personalize.

Step 2

If you are using JDeveloper then, follow these steps

  • Open Oracle JDeveloper and use File/Open option to select the Personalize.jws from the Personalize directory.
  • Next, select Project/Make Personalize.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 Oracle Application Server
    • In step 2, enter user name and password
    • In step 3, enter Enterprise Manager's host name, port number and Remote Application Server home directory(required only if deployed on remote machine).
    • In step 4, click Next and Test the connection. Click Finish button.
  • Now, Right click Personalize.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 Personalize.ear from <SAMPLE_HOME>/deploy/Personalize.ear
  • Enter the Application name as Personalize and click next
  • Enter URL mapping as /Personalize 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>/Personalize/welcome.html

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

For Example, http://incq185b.idc.oracle.com:7777/Personalize/welcome.html

Steps to run the application

  • Open two browser window and enter the above url in both of them.
  • Enter your name in first browse and submit.
  • Enter the name of your friend in other browser and submit ( Since the cached page expires in 60 seconds any page request within 60 seconds will have same timestamp).
  • In first browser you should see your name with time stamp.
  • In second browser you should see your friends name with the same time stamp. 

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