Skip Headers

Oracle Application Server Containers for J2EE JSP Tag Libraries and Utilities Reference
10g (9.0.4)

Part Number B10319-01
Go To Documentation Library
Home
Go To Table Of Contents
Contents
Go To Index
Index

Go to previous page Go to next page

6
JESI Tags for Edge Side Includes

This chapter describes the Edge Side Includes for Java (JESI) tag library that is supplied with OC4J. These tags operate on top of an Edge Side Includes (ESI) framework that is available in the Oracle Application Server Web Cache to provide ESI caching functionality in a JSP application.

The chapter consists of the following sections:

For an overview of Web caching, including a discussion of the OracleAS Web Cache, the Oracle Application Server Java Object Cache, and the OC4J Web Object Cache, see "Summary of Oracle Caching Support for Web Applications".


Note:

The JESI specification is not yet finalized. Although every effort has been made to comply with the latest working version, it is not possible to assure that the OC4J 9.0.4 implementation will fully comply with the final version of the JESI specification.


Overview of Edge Side Includes Technology and Processing

JESI tags, which are used to break down dynamic content of JSP pages into cacheable components, are based upon the Edge Side Includes architecture and markup language.

Although the use of JESI tags does not depend on any particular ESI processor or caching system, a typical scenario among Oracle customers is to use the OracleAS Web Cache and its ESI processor.

The following sections provide background information about some of the underlying technology upon which the Oracle JESI tags are based.

This discussion provides only a brief overview of the ESI architecture and language. For additional information about ESI technology, refer to the following Web site:

http://www.esi.org

Edge Side Includes Technology

This section introduces the features of ESI technology and the concept of ESI surrogates.

Introduction to ESI

Edge Side Includes is an XML-style markup language that allows dynamic content assembly at the "edge" of the network, away from the origin Web server, and is designed to take advantage of available tools such as Web caches and content delivery networks (CDNs) to improve performance for users.

ESI provides a way to reduce the load on Web and application servers by promoting processing on intermediaries, known as surrogates or reverse proxies, that understand the ESI language and act on behalf of the Web server. ESI content is intended for processing somewhere between the time it leaves the originating Web server and the time it is displayed in the user's browser. A surrogate is commanded through HTTP headers. Such a surrogate can be referred to as an ESI processor and can be included as part of the functionality of a Web cache.

ESI lends itself to a partial-page caching methodology, where each dynamic portion of a Web page can be cached individually and retrieved separately and appropriately.

Using the ESI markup tags, a developer can define aggregate Web pages and the cacheable components that are to be retrieved and assembled, as appropriate, by the ESI processor for viewing in the HTTP client. Think of an aggregate page, which is the resource associated with the URL that a user specifies, as a container for assembly. This includes retrieval and assembly instructions that are specified through the ESI tags.


Note:

A JESI user does not have to (and would typically not want to) use ESI tags directly. JESI tag handlers translate JESI tags to ESI tags behind the scenes.


More About Surrogates

Because surrogates act on behalf of Web servers, where page content is owned, they allow content owners to have sufficient control over their behavior. In this way, they offer greater potential for performance improvements than would otherwise be available.

The caching process in surrogates operates similarly to the caching process in HTTP, using similar freshness and validation mechanisms as the foundation. However, surrogates also possess additional control mechanisms.

Key ESI Features

Version 1.0 of the ESI language includes the following key areas of functionality:

Figure 6-1 ESI Include Model

Text description of esiincl.gif follows.

Text description of the illustration esiincl.gif

Oracle Application Server Web Cache and ESI Processor

This section introduces the OracleAS Web Cache and its ESI processor. See the Oracle Application Server Web Cache Administrator's Guide for more information.

Introduction to Oracle Application Server Web Cache

Oracle offers OracleAS Web Cache to help e-businesses manage Web site performance issues. It is a content-aware server accelerator, or reverse proxy server, that improves the performance, scalability, and availability of Web sites that run on the Oracle Application Server.

By storing pages from frequently accessed URLs in memory, OracleAS Web Cache eliminates the need to repeatedly process requests for those URLs on the application Web server. Unlike legacy proxy servers that handle only static documents, OracleAS Web Cache caches both static content and dynamically generated content from one or more application Web servers. As the result of more frequent cache hits, performance enhancement is greater than with legacy proxies and the load on application servers is less.

Conceptually, OracleAS Web Cache is positioned in front of application Web servers, caching their content and sending that content to Web browsers that request it. When Web browsers access the Web site, they send HTTP protocol or HTTPS protocol requests to OracleAS Web Cache, which, in turn, acts as a virtual server for the application Web servers. If the requested content has expired, has been invalidated, or is no longer accessible, then OracleAS Web Cache retrieves the new content from the application Web servers.

Steps in Oracle Application Server Web Cache Usage

Here are the steps for typical browser interaction with OracleAS Web Cache:

  1. A browser sends a request to the Web site of a company.

  2. The request, in turn, generates a request to the Domain Name System (DNS) for the IP address of the Web site.

  3. DNS returns the IP address of OracleAS Web Cache.

  4. The browser sends the request for the Web page to OracleAS Web Cache.

  5. If the requested content is in its cache, then OracleAS Web Cache sends the content directly to the browser. This is known as a cache hit.

  6. If OracleAS Web Cache does not have the requested content, or if the content is outdated or invalid, then the Web cache hands off the request to the application Web server. This is known as a cache miss.

  7. The application Web server sends the content through OracleAS Web Cache.

  8. OracleAS Web Cache sends the content to the client and makes a copy of the page in cache.


Note:

A page that is stored in the cache is removed at some point after it becomes invalid or outdated.


Oracle Application Server Web Cache ESI Processor

OracleAS Web Cache includes an ESI processor to support the use of the Edge Side Includes markup language in caching. (See "Edge Side Includes Technology".)

Web developers in an OracleAS Web Cache environment can use the ESI language directly in their applications; however, for JSP developers, there are several reasons to use the JESI tag library that is provided as a convenient JSP interface to the ESI language. See "Advantages of JESI Tags".

Overview of JESI Functionality

The following sections introduce JESI functionality and the Oracle implementation:

You can access the proposed JESI specification at the following Web site:

http://www.esi.org

Advantages of JESI Tags

OC4J provides the JESI tag library as a convenient interface to ESI tags and Edge Side Includes functionality for Web caching. Developers have the option of using ESI tags directly in any Web application, but JESI tags provide additional convenience for JSP pages. Here are the main advantages in using JESI tags instead of using ESI tags directly:

Overview of JESI Tags Implemented by Oracle

The Oracle implementation of JESI is layered on top of the standard ESI framework. It also conforms with the pending (as of the OC4J 9.0.4 implementation) JESI standard, JSR-128, which is sponsored by the Java Community Process (JCP) organization. For more information about the JCP organization and the status of JSR-128, go to the following location:

http://www.jcp.org

Because the JESI tag library is a standard implementation, note the following:

The Oracle JESI tag library supports the following tags:

JSP developers use these tags (such as JESI include) instead of corresponding ESI tags (such as esi:include). The usefulness and convenience of this is discussed in "Advantages of JESI Tags".


Note:

The Oracle JESI tag library is implemented according to general standards for JSP custom tag libraries. For information about the standard JavaServer Pages tag library framework, refer to the Oracle Application Server Containers for J2EE Support for JavaServer Pages Developer's Guide.


JESI Usage Models

There are two models for how to use JESI tags to define aggregate pages and their cacheable components:

This section describes these models and concludes with some special notes about the JESI include tag.

Control/Include Model

The control/include approach to using JESI tags is modular, typically bringing most (or all) cacheable content into the aggregate page as included pages. This is particularly convenient when you are developing new pages. Use this model as follows:

Each included file is a distinct cacheable object (although caching can be disabled according to tag settings), and any content in the top-level page is also a distinct object.

Both tags are optional, depending on the situation. A page can have a JESI control tag without any JESI include tags. In fact, this is a simple way to convert an existing page for JESI use. There is also no requirement for a JESI control tag in a page that uses JESI include tags. The ESI processor will be appropriately notified of the presence of the JESI include tags, regardless. And there is no requirement for an included page to have a JESI control tag.

The cacheability of a page, either top-level or included, is determined as follows:

See the following sections for tag syntax and examples:

Template/Fragment Model

In the template/fragment approach, content is contained in a single page and you split the page into separately cacheable fragments as desired. This model is particularly convenient when you are converting existing pages for JESI use and want certain portions to be separate cacheable components. Use this model as follows:

The JESI template tag and JESI fragment tag are always used together. If you do not need separate fragments in a page, use the JESI control tag instead of the JESI template tag.

Each fragment is a distinct, cacheable object. Any content at the template level, outside any fragments, is a distinct, cacheable object. Any page that is included through a JESI include tag is also a distinct, cacheable object.

Cacheability is determined as follows:


Note:

It is permissible for the template/fragment model to be used in a response that has already processed a JESI control tag. This might be required, for example, in a case where conditional generation of the aggregate response can include response from any of a set of alternative pages. In this case, the JSP container uses the attribute settings of the control tag, ignores the attribute settings of the template tag, but notes the fact that there is a template tag properly enclosing any fragment tags, as required. As is always the case in the template/fragment model, there must be no cacheable content outside the template tag.


Because the template and fragments are independent, cacheable objects, they can expire at different times in the ESI processor. When a cache miss occurs or an object that has expired is requested, the ESI processor makes a request to the origin server (OC4J in the case of Oracle Application Server) for a fresh copy.

If a requested object is a JESI template, the JSP container executes code in the page that is outside any fragments. In output that is generated by the JSP translator, the translator also places ESI markup that designates where all the fragments should be included. The code that is contained in the JESI fragments will not be executed at that time. Figure 6-2, which follows, illustrates this.

Figure 6-2 JESI Request for Template

Text description of jesitreq.gif follows.

Text description of the illustration jesitreq.gif

When a fragment expires, the ESI processor makes a request to the origin server for that particular fragment. To execute a fragment, the OC4J JSP container executes the template code (code outside of any fragments) plus the code of the fragment being requested. The template code is executed to allow a fragment to rely on certain side effects, such as declaration or initialization of variables.

The output of the fragment code is returned in the response; the output of the template code is discarded. Upon receiving the response, the ESI processor will cache the updated copy of the fragment. Figure 6-3, which follows, illustrates this.

Figure 6-3 JESI Request for Fragment

Text description of jesifreq.gif follows.

Text description of the illustration jesifreq.gif


Note:

To avoid needlessly repeating the execution of expensive template code, strategically place the code within JESI codeblock tags. Configure each codeblock tag according to when you want the code within it to be executed (whenever the template is requested, whenever a fragment is requested, or always).


Remember this behavior when choosing code placement and expiration policies for your templates and fragments. In particular, because template code is executed in every update request, be aware of where you place any expensive code. Do not place an expensive computation at the template level unless it must be executed every time or is appropriately placed within a codeblock tag. Otherwise, place expensive computation in a fragment that has as long an expiration time as possible.

Figure 6-4 shows one codeblock tag scenario, in which the code block is to be executed only when a fragment is requested. In this figure, the request is for the template, so the code block is not executed.

Figure 6-5 shows another codeblock tag scenario, in which the code block is still to be executed only when a fragment is requested. This time, however, the request is for the fragment, so the code block is executed.

Figure 6-4 JESI codeblock Fragment Execution with Request for Template

Text description of jesicbt.gif follows.

Text description of the illustration jesicbt.gif

Figure 6-5 JESI codeblock Fragment Execution with Request for Fragment

Text description of jesicbf.gif follows.

Text description of the illustration jesicbf.gif

Additionally, remember that no two fragments are ever executed during the same request. For example, you should not declare or set the value of a scriptlet variable in one fragment and depend on that variable or the set value in another fragment. If a variable is needed in more than one fragment, then it should be declared and set in the template code (possibly inside a codeblock tag). Similarly, do not set a request or session attribute in one fragment and then try to read it in another fragment. Such "page-global logic" should also be placed at the template level.

Finally, remember that the different fragments of a page will be refreshed at different times, according to invalidation messages and expiration settings. Typically, in a well-tuned application, most fragments would be served from the ESI cache, having to be regenerated only infrequently.


Note:

Beginning with the OC4J 9.0.4 implementation, you can intersperse JESI template, JESI fragment, and JESI include tags with jsp:include tags if the JESI tags follow JESI rules and are properly nested with respect to each other. For example, you can have a page with a JESI template tag, have a jsp:include tag within the template tag, and have JESI fragment tags in the included page. You can also use the JESI template tag within an included page if there is no other template tag at a higher level, and if all output to the response buffer is within the template tag.


See the following sections for tag syntax and examples:

Notes About JESI and JSP Includes

In using either the control/include or template/fragment model, be aware of the following notes regarding the JESI include statement:

Invalidation of Cached Objects

There might be situations where cached objects must be explicitly invalidated due to external circumstances, such as changes to relevant data in a database. There might also be situations where execution of one page might invalidate the data of cached objects corresponding to another page.

For this reason, JESI provides the JESI invalidate tag and related subtags. These tags allow you to invalidate pages based on appropriate combinations of the following:

Invalidation messages are in an XML-based format and specify the URLs to be invalidated. These messages are initiated by the JSP container when it executes the JESI invalidate tag, and transmitted to the cache server over HTTP using a POST method. The cache server then replies with an invalidation response, sent back over HTTP.

See "Descriptions of Tags and Subtags for Invalidation of Cached Objects" for tag syntax and examples.

Personalization of Cached Pages

Dynamic Web pages frequently display customized information tailored to each individual user. For example, a welcome page might display the user's name and a special greeting, or current quotes for stocks the user owns.

For this kind of tailored output, the Web page depends on cookie information, which can be provided through the JESI personalize tag. Without this tag to inform the ESI processor of the need to perform cookie substitution, the Web page cannot be shared by multiple users at the ESI level.

See "Description of Tag for Page Personalization" for tag syntax and examples.


Note:

Do not confuse this tag with the Oracle Application Server Personalization tag library, which encompasses much more functionality. JESI personalization consists of the ESI processor replacing placeholders in a cached page with dynamic strings that come from cookies sent in a request or response. This process enables different users to share the same cached page. OracleAS Personalization, using data mining on the back-end, is much more dynamic and comprehensive. It produces output that changes automatically, according to user activity. See Chapter 10, "Personalization Tags" for more information.


JESI Fallback Execution

If no ESI processor is available for a page that uses JESI tags (such as on a system without OracleAS Web Cache, or in which Web Cache or its ESI processor is down), then the OC4J JSP container steps in to assemble the pages appropriately. Essentially, it takes over and provides the most crucial functionality to execute the pages properly. Caching does not take place, nor does error-checking of JESI tag attribute values.

In these circumstances, the JSP container processes the particular JESI tags as follows:


Note:

In this circumstance, unlike with JESI include functionality, there is no longer a separate response object for an included page.


Oracle JESI Tag Descriptions

The following sections describe the syntax and attributes of the JESI tags provided with OC4J, followed by usage examples:

Note the following requirements for the JESI tag library:

Refer to the Oracle Application Server Containers for J2EE Support for JavaServer Pages Developer's Guide for information about taglib directives, the well-known tag library directory, TLD files, and the meaning of uri values.


Notes:

  • The prefix "jesi:" is used in the tag syntax here. This is by convention and is not required. You can specify any desired prefix in your taglib directive.

  • See "Tag Syntax Symbology and Notes" for general information about tag syntax conventions in this manual.


Descriptions of Tags for Dynamic Caching

The following sections cover the use of JESI tags for dynamic caching, document their syntax and attributes, and provide examples:

See "JESI Usage Models" for overviews of the control/include and template/fragment models.

JESI control Tag

The JESI control tag controls caching characteristics for JSP pages in the control/include usage model. You can use a JESI control tag in the top-level page or any included page, but it is not mandatory. For any page without a JESI control tag in the control/include model, cacheability is according to the configuration settings of the ESI processor. (See "JESI Usage Models".)

Because action resulting from the JESI control tag sets the HTTP response header, this tag should appear as early as possible in the page, before any other JESI tags or any buffer flushes in the page.

Note the following:

Syntax

<jesi:control
             [ expiration = "value" ]
             [ maxRemovalDelay = "value" ]
             [ cache = "yes" | "no" | "no-remote" ] 
             [ control = "uninterpreted_string" ] />
Attributes


Note:

This is a change from the default value of 300 prior to the OC4J 9.0.4 implementation, to conform with the proposed JESI specification.



Notes:


JESI include Tag

The JESI include tag, as with a standard jsp:include tag, allows dynamic insertion of output from the included page into output from the originating page. It does so by directing the ESI processor to process and assemble the included pages. Each included page is a separate cacheable object (but might not be cached, depending on settings).

You can use this tag in either the control/include model or the template/fragment model, in any of the following scenarios:

(See "JESI Usage Models".)

In addition, it is permissible to nest JESI includes, either by using a JESI include tag inside a page that is itself included through a JESI include tag, or by using a JESI include tag inside a page that is included through a standard jsp:include tag.

The cacheability of an included page is determined as follows:

Syntax

<jesi:include page = "uri"
            [ alt = "alternate_uri" ]
            [ ignoreError = "true" | "false" ]
            [ flush = "true" | "false" ] 
            [ copyParam = "true" | "false" ] >

...optional jesi:param tags, related scriptlets...

</jesi:include>


Notes:

  • As with standard jsp:include tags and their optional jsp:param subtags, you can use JESI param tags nested within a JESI include tag to specify new parameters that will be sent to the originating page (the page with the JESI include tag). See "JESI param Tag" for tag syntax. In addition, the body of a JESI include tag can contain scriptlet code to be used in evaluating the added parameters. Output from the scriptlet code, however, and from the body of any JESI include tag in general, is discarded.

  • In some cases, JESI include tags behave differently from jsp:include tags. This is because the JESI include tag results in separate request and response objects for the included page. A JESI include tag is not suitable, for example, when the originating page sets a request attribute and the included page reads this attribute from the request object.

  • For backward compatibility, the deprecated "copyparam" form of the copyParam attribute is accepted. The change from copyparam to copyParam was made to comply with the proposed JESI specification. It is likely that copyparam will be desupported at some point.


Attributes

JESI param Tag

The JESI param tag is an optional subtag of the JESI include tag. These tags work together in the same way that standard jsp:include and jsp:param tags work together.

You can use one or more JESI param subtags to pass additional query parameters to the target page of the JESI include tag. Doing this is more straightforward than the alternative, which is to specify parameters in the page URI of the JESI include tag. If you use both mechanisms, then parameters from param tags are appended after parameters from the include tag page URI. Any parameters that are copied from the original request, through an include tag copyParam="yes" setting, are appended after parameters from JESI param tags.

See "Example 5: Control/Include with param Tag" for a sample.


Note:

Be aware that the parameter name and value will be evaluated when the originating page (the page with the JESI include and param tags) is generated. If, afterward, the originating page is cached in an ESI processor, then the name and value of the parameter, passed down to the included page, remain unchanged until the originating page is regenerated. (This is similar to the treatment of request parameters that are copied from the request through a copyParam="true" setting.)


Syntax

<jesi:include page = "uri" ... >
   <jesi:param name="param_name" 
         value="param_value" />
   ...
</jesi:include>
Attributes

Examples: Control/Include Model

This section provides examples of JESI tag usage in the control/include model.

Example 1: Control/Include

The following example employs default cache settings; no JESI control tag is necessary. The JESI include tags specify no alternate files, and a "file not found" error will halt processing. The flush attribute is permissible, but ignored.

<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/jesitaglib.tld"
           prefix="jesi" %>
<html>
<body>
<jesi:include page="stocks.jsp" flush="true" />
<p>
<hr>
<jesi:include page="/weather.jsp" flush="true" />
<p>
<hr>
<jesi:include page="../sales.jsp" flush="true" />
</body>
</html>
Example 2: Control/Include

This example uses the JESI control tag to specify nondefault cache settings for maxRemovalDelay and expiration. In addition, it explicitly enables caching of the page, though this is already enabled by default. The first JESI include tag specifies an alternate page in case order.jsp cannot be retrieved by the ESI processor, and specifies that processing should continue even if neither page can be retrieved. The second JESI include tag specifies no alternate page; processing will halt if the page cannot be retrieved.

<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/jesitaglib.tld"
           prefix="jesi" %>

<jesi:control maxRemovalDelay="1000" expiration="300" cache="yes"/>
<jesi:include page="order.jsp" alt="alt.jsp" ignoreError="true"/>
<jesi:include page="commit.jsp" />
Example 3: Control/Include

This example is of an aggregate page with conditional output. A cookie represents the identity of a customer. If no cookie is found, the user will be shown a generic welcome page with general product information. If a cookie is found, the user will be shown a list of products according to the user profile. This list is brought into the page through a JESI include statement.

The JESI control tag also sets nondefault values for maxRemovalDelay and expiration and explicitly enables caching for the page.

<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/jesitaglib.tld"
           prefix="jesi" %>

<jesi:control maxRemovalDelay="1000" expiration="300" cache="yes"/>
<%
  String customerId=CookieUtil.getCookieValue(request,"customerid");

  if (customerId==null) {

    // some unknown customer 
%>
    <jesi:include page="genericwelcome.jsp" />
<%
  }
  else {

    // a known customer; trying to retrieve recommended products from profiling

    String recommendedProductsDescPages[]=
               ProfileUtil.getRecommendedProductsDescURL(customerId);

    for (int i=0; i < recommendedProductsDescPages.length; i++) {
%>
    <jesi:include page="<%=recommendedProductsDescPages[i]%>" />
<%
    }
  }
%>
Example 4: Control/Include

This example illustrates the use of JESI include statements with request parameters. Assume that the main page is accessed through the following URL:

http://host:port/application1/main.jsp?p2=abc

The main page takes the parameter setting p2=abc. Here is that page:

<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/jesitaglib.tld"
           prefix="jesi" %>
<html> 
<jesi:control cache="no" /> 
<jesi:include page="a.jsp?p1=v1" /> 
<h3>hello ...</h3> 
<jesi:include page="b.jsp" /> 
<h3>world ...</h3> 
<jesi:include page="c.jsp?p1=v2" copyParam="true" /> 
</html> 

The a.jsp page takes the parameter setting p1=v1. The c.jsp page takes the setting p1=v2 as well as the setting p2=abc, as a result of the copyParam setting and the p2 setting in the URL for the main page.

Additionally, the top-level page is noncacheable, according to the cache="no" setting. In fact, remember that you should use the copyParam setting in a JESI include tag only when the originating page is noncacheable, because the request attributes might change from one request to the next. Remember, too, that the cache="no" setting has no effect on the included pages. They are still cacheable by default. In other words, each is cacheable unless it has its own JESI control tag with cache="no" for some reason.

Example 5: Control/Include with param Tag

This example illustrates use of a JESI param tag to add runtime values as new parameters to the included page request. Assume the main page is accessed through a URL such as the following, taking the parameter setting p1=v1:

http://host:port/application/main.jsp?p1=v1

Here is the page:

<jesi:control cache="yes" />
<jesi:include page="a.jsp" >
   <% String v2 = null;
      if(request.getParameter("p1").equals("v1")
          v2 = "v1 set";
      else
          v2 = "v2 unset";
   %>
   <jesi:param name="p2" value="<%=v2%>" />
</jesi:include>

JESI template Tag

Use the JESI template tag to specify caching behavior for the template content, outside any fragments, in the template/fragment usage model. (See "JESI Usage Models".) The corresponding HTTP header will be set according to the ESI specification. The content outside the fragments is referred to here as the template content and is a separate cacheable object, and the content of each fragment set aside with a JESI fragment tag is a separate cacheable object.


Important:

All response output must be generated between the template start-tag and end-tag. Place the JESI template start-tag as early in the page as possible. It must appear before any JESI fragment tags or any buffer flushes in the page. It must also appear before any other visible output content such as text, HTML markup, new lines, or white space. Place the JESI template end-tag as late in the page as possible, after any JESI fragment tags and any other visible output content.


Always use the JESI template tag together with JESI fragment tags. If you have no need for separate fragments, then use a JESI control tag instead of a JESI template tag.

Note the following:


Note:

In this situation, the template tag is not ignored completely. When the template/fragment model is used in a page that also has a JESI control tag (which can happen if a page with a template tag is included dynamically, and usually conditionally), the JSP container notes the fact that there is a template tag properly enclosing any fragment tags, as required.


The JESI template tag has the same attributes, with the same usage, as the JESI control tag.

Syntax

<jesi:template
             [ expiration = "value" ]
             [ maxRemovalDelay = "value" ]
             [ cache = "yes" | "no" | "no-remote" ] 
             [ control = "uninterpreted_string" ] >

...page content, jesi:fragment tags, optional jesi:include tags, optional 
jesi:codeblock tags..

</jesi:template>
Attributes

For attribute descriptions, see "JESI control Tag".

JESI fragment Tag

Use one or more JESI fragment tags within a JESI template tag, between the JESI template start-tag and end-tag, in the template/fragment model. (See "JESI Usage Models".) Each JESI fragment tag defines a separate fragment of the JSP page, as desired, for caching behavior. Each fragment is a separate cacheable object.

When a particular fragment is requested for inclusion into the aggregate response through the ESI mechanism, the ESI processor retrieves only that fragment.

The JESI fragment tag has the same attributes, with the same usage, as the JESI control and JESI template tags.

Note the following:

Syntax

<jesi:fragment
             [ expiration = "value" ]
             [ maxRemovalDelay = "value" ]
             [ cache = "yes" | "no" | "no-remote" ]
             [ control = "uninterpreted_string" ] >

...JSP code fragment...

</jesi:fragment>
Attributes

For attribute descriptions, see "JESI control Tag".

JESI codeblock Tag

In the template/fragment model, you can optionally use one or more JESI codeblock tags within template code, outside of any fragments, to mark conditional execution of particular blocks of code. Each codeblock tag surrounds a block of code and specifies when it should be executed:

or:

or:

Without use of this tag, all template code is executed with every request--with each request for the template as well as with each request for any fragment, although template output is discarded in the case of a request for a fragment.

Although it is important to execute the template whenever a fragment is requested--to allow fragments to depend on template code side effects such as variable declaration or initialization--there might be blocks of code that are not critical to fragments. You can place any such code block into a codeblock tag with a specification to execute the block only when the template is requested.

Alternatively, there might be blocks of template code that are potentially vital to all fragments, but not to the template itself. You can place any such code block into a codeblock tag with a specification to execute the block only when any fragment is requested.


Note:

It is advisable to not generate any visible output within a JESI codeblock tag. This is to avoid unexpected behavior due to differences in execution between requests for the template and requests for fragments. If execute="template" (or "always") and the template is requested, then the code is executed and the content is output, as presumably intended. However, if execute="fragment" (or "always") and the request is for a fragment, then the code is executed but the entire output of the template is suppressed, as is always the case when a fragment is requested. See Figure 6-3 in "Template/Fragment Model".


Syntax

<jesi:template ... >
...
   <jesi:codeblock execute = "template" | "fragment" | "always" >
      ...request-dependent JSP content...
   </jesi:codeblock>
...
</jesi:template>
Attributes

Examples: Template/Fragment Model

This section contains examples of JESI tag usage in the template/fragment model.

Example 1: Template/Fragment

This is a general example showing use of the JESI template and JESI fragment tags. Because only the expiration attribute is set in any of the tags, all other settings are according to defaults. The setting of the cache attribute defaults to "yes", so the template and all three fragments are cached.

The template content (outside the fragments) uses an expiration of 3600 seconds, according to the JESI template tag. This applies to all the HTML blocks because they are outside the fragments. JSP code block #1 is cached with an expiration setting of 60; JSP code block #2 is cached with the default expiration setting; and JSP code block #3 is cached with an expiration setting of 600.

<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/jesitaglib.tld"
           prefix="jesi" %>
<jesi:template expiration="3600"> 
...HTML block #1...
   <jesi:fragment expiration="60"> 
   ...JSP code block #1...
   </jesi:fragment> 
...HTML block #2...
   <jesi:fragment> 
   ...JSP code block #2...
   </jesi:fragment> 
...HTML block #3...
  <jesi:fragment expiration="600"> 
   ...JSP code block #3...
   </jesi:fragment> 
...HTML block #4...
</jesi:template> 
Example 2: Template/Fragment

This example employs JESI include tags inside the fragments. The following are the cacheable objects for this page:

<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/jesitaglib.tld"
           prefix="jesi" %>
<jesi:template expiration="3600"> 
...HTML block #1...
   <jesi:fragment expiration="60"> 
   ...JSP code block #1...
   <jesi:include page="stocks.jsp" />
   </jesi:fragment> 
...HTML block #2...
   <jesi:fragment> 
   ...JSP code block #2...
   <jesi:include page="/weather.jsp" />
   </jesi:fragment> 
...HTML block #3...
   <jesi:fragment expiration="600"> 
   ...JSP code block #3...
   <jesi:include page="../sales.jsp" />
   </jesi:fragment> 
...HTML block #4...
</jesi:template>
Example 3: Template/Fragment with Codeblock

This is a conceptual example of how you can use the codeblock tag in the template/fragment model. In this case, to improve performance, the code that connects to the database would be placed in the code block so that it is not reexecuted needlessly.

<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/jesitaglib.tld"
           prefix="jesi" %>
<jesi:template>
Welcome to the Frequent Flyer Home page!
<jesi:codeblock execute="fragment" >
  /* Open a database connection and store it in the variable dbConn. */
</jesi:codeblock>
BEST DEALS
<jesi:fragment expiration="600" maxRemovalDelay="180"> 
...in Air Travel
/* Select the three cheapest USA domestic round-trip fares, using the database 
connection stored in dbConn. */
</jesi:fragment> 

<jesi:fragment expiration="600" maxRemovalDelay="180"> 
...in Accommodations 
/* select the three best hotel deals, using the database connection stored in 
dbConn. */
</jesi:fragment>

Click here to access your current Mileage account <...>
</jesi:template>

Descriptions of Tags and Subtags for Invalidation of Cached Objects

Use the JESI invalidate tag and the following subtags, as appropriate, to explicitly invalidate cached objects in the ESI processor:

The following sections cover the syntax of these tags, the JESI configuration file (which can be used to specify the user name, password, and URL to log in for invalidation), and some examples:

See "Invalidation of Cached Objects" for an overview.

JESI invalidate Tag

Use the JESI invalidate tag with its JESI object subtag to explicitly invalidate one or more cached objects.

Use the subtags as follows:

Syntax

<jesi:invalidate
             [ url = "url"
               username = "user_name"
               password = "password" ]
             [ config = "configfilename" ]
             [ output = "browser" ] >

Required subtag (described in "JESI object Subtag"):

             <jesi:object ... >

Optional subtag of JESI object (described in "JESI cookie Subtag"):

                   <jesi:cookie ... />

Optional subtag of JESI object (described in "JESI header Subtag"):

                   <jesi:header ... />

             </jesi:object>

</jesi:invalidate>

Either specify the user, password, and URL all through their individual attributes, or all in the configuration file that is either referred to in the config attribute or is found in the default location. The default location is /WEB-INF/jesi.xml or, for backward compatibility, /WEB-INF/config.xml. See "JESI Configuration File" for information about the file. If the user name, password, and URL are specified through the configuration file as well as through the attribute settings, then the attribute settings take precedence.

If you specify a <user> element for the OracleAS Web Cache "invalidator" account in the OC4J jazn-data.xml file, then you can use special syntax in the password attribute to refer to the information in jazn-data.xml instead of specifying the password in clear text. The password is specified in jazn-data.xml in an obfuscated form. See the username and password attribute descriptions below. See the Oracle Application Server Containers for J2EE Security Guide for information about the jazn-data.xml file.


Note:

It is permissible to have multiple object tags within an invalidate tag.


Attributes

JESI Configuration File

The proposed JESI specification supports the use of a configuration file. Currently, you can use a configuration file only to specify the user name, password, and URL for invalidation. (Alternatively, you can specify the user name, password, and URL through attributes of each JESI invalidate tag. See "JESI invalidate Tag".)

A JESI configuration file must have a <jesi-config> top-level element, an <invalidation> subelement under that, and <username>, <password>, and <url> subelements under the <invalidation> element.


Note:

For backward compatibility, the deprecated elements <ojsp-config> and <web-cache> are currently acceptable instead of <jesi-config> and <invalidation>, respectively. The new elements are to comply with the proposed JESI specification. It is likely that the <ojsp-config> and <web-cache> will be desupported in a future release.


In the current implementation there are two possible default files, or you can place the file anywhere within your application and specify its name and location through the config attribute of the invalidate tag, specifying either an application-relative or a page-relative location.

As of the OC4J 9.0.4 implementation, the preferred default file is /WEB-INF/jesi.xml, which conforms with the proposed JESI specification. For backward compatibility, the previous default file, /WEB-INF/config.xml, is also supported.

The following precedence is used to obtain the user name, password, and URL for invalidation:

  1. If the JESI invalidate tag specifies the username, password, and url attribute settings (all three), then those values are used.


Note:

If the invalidate tag specifies one or two of these attributes but not all three, an exception is raised. An exception is also raised if one or more of the attribute values is an empty string or null.


  1. If you do not specify username, password, and url in the invalidate tag, but the config attribute specifies a configuration file, then values from the specified configuration file are used.

  2. If you do not specify username, password, url, and config in the invalidate tag, then the JSP container attempts to use a default configuration file. First, the container searches for /WEB-INF/jesi.xml and uses the settings from that file if it is found. If that file is not found, then the container searches for /WEB-INF/config.xml and uses the settings from that file if it is found.


Notes:

If the invalidate tag does not specify the user name, password, and URL, an exception is thrown under either of the following circumstances:

  • If at any point a configuration file is found that does not specify all three attributes

  • If no configuration file is found


If the OC4J jazn-data.xml file contains a <user> element for the OracleAS Web Cache "invalidator" account, you can that account name in the JESI configuration file and get the password from jazn-data.xml by using special right-arrow syntax with a dash ("-") and right-carrot (">"), followed by the invalidator account name. See "Example 2: Configuration File Obtaining Password from jazn-data.xml" below.

Example 1: Configuration File with Clear Text for Password

The following example shows a configuration file that is used instead of the url, username, and password attributes to set the URL and login information:

<?xml version="1.0" ?>
<jesi-config>
  <invalidation>
      <url>http://yourhost.yourcompany.com:4001</url>
      <username>invalidator</username>
      <password>invpwd</password>
  </invalidation>
</jesi-config>
Example 2: Configuration File Obtaining Password from jazn-data.xml

The following example, instead of using clear text to specify the password, uses special "->" syntax to obtain the de-obfuscated password from the jazn-data.xml file. This example assumes jazn-data.xml contains a <user> element for the OracleAS Web Cache "invalidator" account:

<?xml version="1.0" ?>
<jesi-config>
  <invalidation>
      <url>http://yourhost.yourcompany.com:4001</url>
      <username>invalidator</username>
      <password>->invalidator</password>
  </invalidation>
</jesi-config>

JESI object Subtag

Use the required JESI object subtag of the JESI invalidate tag to specify cached objects to invalidate, according to either the complete URI or a URI prefix. Optionally, use JESI cookie subtags or JESI header subtags (or both) to specify further criteria for invalidation, based on cookie or HTTP header information.

Specify either the complete URI or the URI prefix in the uri attribute setting. Whether this field is interpreted as a full URI or as a prefix depends on the setting of the prefix attribute.

Syntax

<jesi:object uri = "uri_or_uriprefix"
           [ maxRemovalDelay = "value" ]
           [ prefix = "yes" | "no" ] >

Optional subtag (described in "JESI cookie Subtag"):

                   <jesi:cookie ... />

Optional subtag (described in "JESI header Subtag"):

                   <jesi:header ... />

</jesi:object>

Here is the syntax if you do not use either subtag:

<jesi:object uri = "uri_or_uriprefix"
           [ maxRemovalDelay = "value" ] 
           [ prefix = "yes" | "no"] />


Notes:

  • It is permissible to have multiple object tags within an invalidate tag.

  • It is permissible to have multiple cookie tags or header tags within an object tag.


Attributes

JESI cookie Subtag

Use one or more JESI cookie subtags of the JESI object tag (which is a subtag of the JESI invalidate tag) if you want to use cookie information as further criteria for invalidation. This cookie information is in addition to the URI or URI prefix setting in the JESI object tag, and possibly in addition to JESI header tags as well. The cookie tag is useful for invalidating objects that have had multiple versions cached, based on cookie information.

The cookie tag has no body.

Syntax

<jesi:cookie name = "cookie_name"
           [ value = "cookie_value" ] />


Notes:

  • It is permissible to have multiple cookie tags within an object tag.

  • Unlike most other JESI tag attributes, it is permissible for the value attribute to have a null or empty-string value.


Attributes

For each use of the cookie subtag, the request URL of the object to be invalidated must have a cookie that matches the name attribute setting and, if specified, the value attribute setting.

JESI header Subtag

Use one or more JESI header subtags of the JESI object tag (which is a subtag of the JESI invalidate tag) if you want to use HTTP/1.1 header information as further criteria for invalidation. This header information is in addition to the URI or URI prefix setting in the JESI object tag, and possibly in addition to JESI cookie tags as well. The header tag is useful for invalidating objects that have had multiple versions cached, based on header information.

The header tag has no body.

Syntax

<jesi:header name = "header_name"
             value = "header_value" />


Note:

It is permissible to have multiple header tags within an object tag.


Attributes

For each use of the header subtag, the request URL of the object to be invalidated must have a header that matches the name and value attribute settings.

Examples: Page Invalidation

This section provides examples of page invalidation using the JESI invalidate tag, its JESI object subtag, and the JESI cookie subtag of the JESI object tag.

Example 1: Page Invalidation

This example invalidates a single object in the ESI processor, specified by its complete URI. (By default, the uri attribute of the object tag specifies a full URI, not a URI prefix.) The JESI invalidate tag also specifies the URL for the cache server, and the user name and password for the invalidation account. In addition, it specifies that the invalidation response from the cache server should be displayed in the user's browser.

...
<jesi:invalidate url="http://yourhost.yourcompany.com:4001"
                 username="invalidator" password="invpwd"
                 output="browser">
     <jesi:object uri="/images/logo.gif"/>
</jesi:invalidate>
...
Example 2: Page Invalidation

This example is equivalent to "Example 1: Page Invalidation" immediately above, but uses a configuration file to specify the cache server URL and login information.

...
<jesi:invalidate config="/myconfig.xml" output="browser">
     <jesi:object uri="/images/logo.gif"/>
</jesi:invalidate>
...

The JESI invalidate tag specifies an application-relative location for the configuration file. As an example, suppose myconfig.xml has the following content:

<?xml version="1.0" ?>
<jesi-config>
  <invalidation>
      <url>http://yourhost.yourcompany.com:4001</url>
      <username>invalidator</username>
      <password>invpwd</password>
  </invalidation>
</jesi-config>
Example 3: Page Invalidation

This example invalidates all objects in the ESI processor, according to the URI prefix "/". It does not specify that the invalidation response should be displayed in the browser, so it will not be displayed at all.

...
<jesi:invalidate url="http://yourhost.yourcompany.com:4001"
                 username="invalidator" password="invpwd">
     <jesi:object uri="/" prefix="yes"/>
</jesi:invalidate>
...
Example 4: Page Invalidation

This example invalidates a single object but allows it to be served stale for up to 30 minutes (1800 seconds).

...
<jesi:invalidate url="http://yourhost.yourcompany.com:4001"
                 username="invalidator" password="invpwd">
     <jesi:object uri="/images/logo.gif" maxRemovalDelay="1800"/>
</jesi:invalidate>
...
Example 5: Page Invalidation

This example specifies the same object for invalidation as "Example 1: Page Invalidation", but specifies that it should be invalidated only if its request URL has a cookie named user_type with the value customer.

...
<jesi:invalidate url="http://yourhost.yourcompany.com:4001"
                 username="invalidator" password="invpwd">
     <jesi:object uri="/images/logo.gif">
          <jesi:cookie name="user_type" value="customer"/>
     </jesi:object>
</jesi:invalidate>
...

Description of Tag for Page Personalization

To allow page customization when sharing the same cached page between multiple users, the ESI processor must be informed of dependencies by the page on cookie and session information. Cookie value replacement, for example, occurs in the ESI processor instead of in the Web server.

JESI personalize Tag

Use the JESI personalize tag to allow page customization, by directing the ESI processor to substitute cookie values from a current request before serving a cached page.

The effect of this tag is to insert an ESI placeholder with the cookie name and value into the response body. If the cookie that is specified in the name attribute is found in the request and has a non-null value, its value is used. If the cookie is not found in the request or has a null value, but a value is specified through the default attribute, then a new cookie is created and the default value is used. If the cookie did not previously exist and no default value is specified, the tag has no effect.

The personalize tag has no body.

Syntax

<jesi:personalize name = "cookie_name"
                [ default = "default_value" ] />


Note:

For backward compatibility, the deprecated "value" form of the default attribute is accepted. The change from value to default was made to comply with the proposed JESI specification. It is likely that value will be desupported in a future release.


Attributes

Example: Page Personalization

The following example shows usage of the JESI personalize tag:

<jesi:personalize name="user_id" default="guest" />

The corresponding ESI tag that is generated allows the ESI processor to find the necessary information. In this case, it looks for a cookie named user_id and retrieves its value. If it cannot find the cookie, it uses a default value of "guest".

Handling this cookie-value replacement in the ESI processor allows the ESI processor to serve multiple customized pages from a single cached copy, without involving the application server.

JESI Tag Handling and JESI-to-ESI Conversion

JESI tag handler classes, supplied as part of the JESI tag library with OC4J, provide the bridge from JSP functionality to ESI functionality. Tag handlers generate ESI tags from JESI tags and, as appropriate, generate HTTP requests for invalidation, set HTTP response headers, and so on. Be aware, however, that there is not always a simple one-to-one mapping between JESI tags and ESI tags, or between JESI tag attributes and ESI tag attributes.

Example: JESI-to-ESI Conversion for Included Pages

As an example of JESI-to-ESI conversion, consider the following JSP code:

<p>BEGIN</p> 
<jesi:control cache="no"/>
<jesi:include page="stocks.jsp" flush="true" /> 
<p> 
<hr> 
<jesi:include page="/weather.jsp" copyParam="true" flush="true" /> 
<p> 
<hr> 
<jesi:include page="../sales.jsp?tax=local" copyParam="true" flush="true" /> 
<p>END</p> 

Assume that this JSP code is part of a page with the following URL:

http://host:port/application1/top.jsp

Further assume the following request:

http://host:port/application1/top.jsp?city=Washington_DC

In this case, the JESI include tag handler generates ESI markup such as in the following response.

In the response header:

Surrogate-Control: content="ESI/1.0",max-age=86400+0,no-store

In the response body:

<p>BEGIN</p> 
<esi:include src="/application1/stocks.jsp"/> 

<p> 
<hr> 
<esi:include src="/weather.jsp?city=Washington_DC"/> 

<p> 
<hr> 
<esi:include src="/sales.jsp?tax=local&city=Washington_DC"/> 

<p>END</p> 

This response is read by the ESI processor before being delivered to the client. A Surrogate-Control header alerts the ESI processor that the response body contains ESI markup; therefore, the caching mechanism looks inside the response body for ESI tags. In addition, the Surrogate-Control header sets the cache directive to no-store, according to the cache="no" attribute setting. Expiration and maximum delay interval have no impact in this case.

In response to each of the three esi:include tags, the ESI processor makes an additional request to the URL that is specified. Each response is included into the top-level page, and only after that is the assembled page delivered to the client. Note that the client receives one response, but the cache initially makes four requests to obtain it. This might seem like a lot of overhead; however, the overall efficiency will be improved if many additional requests also use the same included pages, such as weather.jsp. No requests for these pages are required, because they are cached separately on the ESI processor.

Example: JESI-to-ESI Conversion for a Template and Fragment

Suppose that when employees connect to a corporate intranet site, the content of their pages is dynamic except for a few features that are present in every response. In particular, there is always a footer displaying the stock chart and latest business headlines for the company, and the business headlines are obtained from an external business news site. Because all returned pages will have to include the same information, and it is expensive to obtain, it is more efficient to cache the footer in the ESI processor.

The remainder of the page response is dynamic, incorporating the stock fragment in a slightly different way each time. To avoid having to rewrite the page, you can mark the footer as a JESI fragment and the enclosing page as a JESI template.

Also assume that a charity campaign is in progress and that the organizers want to display a bar chart showing their goal amount and the current donation amount as part of all corporate pages. This information is stored in a special database table and is updated twice a day. The chart is a good candidate to be an additional JESI fragment. Therefore, you would add a JESI template tag at the top of the page and use JESI fragment tags to enclose the fragments that are to be cached as separate entities.

Assume that the URL to the corporate page is as follows:

http://www.bigcorp.com/employee_page.jsp

Further assume that you have modified the page as follows:

<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/jesitaglib.tld"
           prefix="jesi" %> 
<jesi:template cache="no" > 

<p>BEGIN</p> 
... some dynamic page content... 
<jesi:fragment> 
This_is_the_body_of_Charity_Chart 
</jesi:fragment> 
... some more dynamic content... 
<jesi:fragment> 
This_is_the_body_of_Business_Footer 
</jesi:fragment> 
</jesi:template>
<p>END</p>

When the page is requested, an HTTP response is generated as follows.

In the response header:

Surrogate-Control: content="ESI/1.0",max-age=86400+0,no-store

In the response body:

<p>BEGIN</p> 
... some dynamic page content... 
<esi:include src="/employee_page.jsp?__esi_fragment=1"/> 
... some more dynamic content... 
<esi:include src="/employee_page.jsp?__esi_fragment=2"/> 
<p>END</p> 

As with the JESI include example in "Example: JESI-to-ESI Conversion for Included Pages", the ESI processor is alerted by the Surrogate-Control response header. Note the no-store directive, generated because of the cache="no" setting in the JESI template tag.

The ESI processor makes two additional requests, where it fetches and caches the two fragments. After that, the composite page is returned to the employee. When the employee works with the page again, the dynamic content will be newly generated but the chart and the footer will be served from the cache.


Note:

Surrogate-Control headers are consumed by the ESI processor and are not seen in the final response to the client.



Go to previous page Go to next page
Oracle
Copyright © 2002, 2003 Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Table Of Contents
Contents
Go To Index
Index