| Oracle
Application Server Containers for J2EE JSP Tag Libraries and Utilities Reference 10g (9.0.4) Part Number A97678-01 |
|
This topic documents tag libraries, JavaBeans, and other utilities supplied with OC4J that are implemented according to JSP standards. There is also a discussion of support for the JavaServer Pages Standard Tag Library (JSTL), and a section summarizing tag libraries provided with other components of the Oracle9i Application Server.
Oracle-specific features, as well as an introduction to the OC4J JSP container, standard JSP technology, and standard JSP 1.2 tag library features, are covered in the Oracle Application Server Containers for J2EE Support for JavaServer Pages Developer's Guide 10g.
This topic covers the following topics:
Tags and JavaBeans introduced in the first section provide functionality in several different areas, including type extensions, integration with XML/XSL, database access, and programming convenience.
The Oracle extensions introduced in this section are implemented through tag libraries or custom JavaBeans that comply with JSP and JavaBeans standards.
Here is a list of the topics covered:
|
Notes:
|
For the syntax documentation in tag descriptions throughout this manual, note the following:
[...]
<%= jspExpression
%>"
taglib directives.
You can use JSP syntax to generate any text-based MIME type, not just HTML code. In particular, you can dynamically create XML output. When you use JSP pages to generate an XML document, however, you often want a stylesheet applied to the XML data before it is sent to the client. This is difficult in JavaServer Pages technology, because the standard output stream used for a JSP page is written directly back through the server.
OC4J provides special tags to specify that all or part of a JSP page should be transformed through an XSL stylesheet before it is output. Input can be from the tag body or from an XML DOM object, and output can be to an XML DOM object to the browser.
You can use these tags multiple times in a single JSP page if you want to specify different style sheets for different portions of the page.
There is additional XML support as well:
XML utility tags are summarized in Table 1-1.
Note that there is also XML functionality in the dbOpen SQL tag
and the cacheXMLObj Web Object Cache tag. For more information,
see "About XML and XSL Tag Support".
You can find information about standard JSP 1.2 XML support in the Oracle Application Server Containers for J2EE Support for JavaServer Pages Developer's Guide 10g.
|
Note: The custom XML tag library provided with OC4J pre-dates the JavaServer Pages Standard Tag Library (JSTL) and has areas of duplicate functionality. Going forward, for standards compliance, it is advisable to use JSTL instead of the custom libraries as a general rule. See "Support for the JavaServer Pages Standard Tag Library". Oracle is not desupporting the existing tags, however. For features in the custom library that are not yet available in JSTL, where there seems to be general usefulness, Oracle will try in the future to have the features adopted into the JSTL standard as appropriate. |
OC4J supplies a set of custom JavaBeans for use in accessing the Oracle9i database. The following beans are provided in the oracle.jsp.dbutil package:
ConnBean opens a database connection. This bean also supports data sources and connection pooling.
ConnCacheBean uses the Oracle connection caching implementation for database connections. (This requires JDBC 2.0.)
DBBean executes a database query.
CursorBean provides general DML support for queries; UPDATE, INSERT, and DELETE statements; and stored procedure calls.
For information, see "JavaBeans for Data Access".
For JSP programmers, OC4J also provides a custom tag library for SQL functionality, wrapping the functionality of the JavaBeans. These tags are summarized in Table 1-2. For further information, see "SQL Tags for Data Access".
|
Note: The custom SQL tag library provided with OC4J pre-dates the JavaServer Pages Standard Tag Library (JSTL) and has areas of duplicate functionality. Going forward, for standards compliance, it is advisable to use JSTL instead of the custom libraries as a general rule. See "Support for the JavaServer Pages Standard Tag Library". Oracle is not desupporting the existing tags, however. For features in the custom library that are not yet available in JSTL, where there seems to be general usefulness, Oracle will try in the future to have the features adopted into the JSTL standard as appropriate. |
OC4J provides utility tags to accomplish the following from within Web applications:
For sending e-mail messages, optionally with server-side or client-side attachments, you can use the oracle.jsp.webutil.email.SendMailBean JavaBean or the sendMail tag. Table 1-6 summarizes the sendMail tag. See "Mail JavaBean and Tag" for more information.
For uploading files, you can use the httpUpload tag or the oracle.jsp.webutil.fileaccess.HttpUploadBean JavaBean. For downloading, there is the httpDownload tag or the HttpDownloadBean JavaBean. Table 1-7 summarizes the file access tags. For more information see "File-Access JavaBeans and Tags".
For using EJBs, there are tags to create a home instance, create an EJB instance, and iterate through a collection of EJBs. Table 1-8 summarizes the EJB tag library. See "EJB Tags" for more information.
There are also utility tags for displaying a date, displaying an amount of money in the appropriate currency, displaying a number, iterating through a collection, evaluating and including the tag body depending on whether the user belongs to a specified role, and displaying the last modification date of the current file. Table 1-9 summarizes these tags. See "General Utility Tags" for more information.
This section provides the following information:
The Oracle tag libraries introduced in this section are JSP standards-compliant.
The Oracle Application Server and OC4J provide the following caching features:
This is an HTTP-level cache, maintained outside the application, providing very fast cache operations. It is a pure, content-based cache, capable of caching static data (such as HTML, GIF, or JPEG files) or dynamic data (such as servlet or JSP results). Given that it exists as a flat content-based cache outside the application, it cannot cache objects (such as Java objects or XML DOM objects) in a structured format. In addition, it has relatively limited post-processing abilities on cached data.
The OracleAS Web Cache provides an ESI processor to support Edge Side Includes, an XML-style markup language that allows dynamic content assembly away from the Web server. This technology enables you to break cacheable pages into separate cached objects, as desired. OC4J supports this technology through its JESI tag library.
For an overview of Edge Side Includes and the OracleAS Web Cache, as well as detailed documentation of the JESI tag library, see "About JESI Tags for Edge Side Includes".
For additional information about the OracleAS Web Cache, see the Oracle Application Server Web Cache Administration and Deployment Guide 10g.
This is an application-level cache, embedded and maintained within a Java Web application. It is a hybrid cache, both Web-based and object-based. A custom tag library or API enables you to define page fragment boundaries and to capture, store, reuse, process, and manage the intermediate and partial execution results of JSP pages and servlets as cached objects. Each block can produce its own resulting cache object. The produced objects can be HTML or XML text fragments, XML DOM objects, or Java serializable objects. These objects can be cached conveniently in association with HTTP semantics. Alternatively, they can be reused outside HTTP, such as in outputting cached XML objects through Simple Mail Transfer Protocol (SMTP), Java Messaging Service (JMS), Advanced Queueing (AQ), or Simple Object Access Protocol (SOAP).
For more information, see "About Web Object Cache Tags and API".
The Oracle9i Application Server Java Object Cache is a general-use cache to manage Java objects within a process, across processes, and on local disk. By managing local copies of objects that are difficult or expensive to retrieve or create, the Java Object Cache significantly improves server performance. By default, the OC4J Web Object Cache uses the Oracle9i Application Server Java Object Cache as its underlying cache repository.
For details, see the Oracle Application Server Containers for J2EE Services Guide 10g.
It is important to understand the role of the OC4J Web Object Cache in the overall setup of a Web application. It works at the Java level and is closely integrated with the HTTP environment of servlet and JSP applications. By contrast, the Oracle Application Server Java Object Cache works at the Java object level, but is not integrated with HTTP. As for the OracleAS Web Cache, it is well integrated with HTTP and is an order of magnitude faster than the Web Object Cache, but it does not operate at the Java level. For example, it cannot apply a stylesheet to a cached DOM object within the J2EE container, reuse the cached result in other protocols, or allow direct DOM operations. (OracleAS Web Cache can, however, apply a stylesheet to raw XML documents, as opposed to DOM objects, that were cached from the original Web server through HTTP.)
The Web Object Cache is not intended for use as the main Web cache for an application. It is an auxiliary cache embedded within the same Java virtual machine that is running your servlets and JSP pages. Because the retrieval path for cached results in the Web Object Cache includes the JVM and the JSP and servlet engines, it generally takes much longer to serve a page from the Web Object Cache compared to the OracleAS Web Cache.
The Web Object Cache does not replace or eliminate the need for either the OracleAS Web Cache or the Oracle Application Server Java Object Cache--it is a complementary caching component in the overall framework of a Web application and should be used together with the other caching products, as appropriate. In fact, the Web Object Cache uses the Java Object Cache as its default repository. And through combined use of the OC4J JESI tags and Web Object Cache tags, you can use the Web Object Cache and OracleAS Web Cache together in the same page.
Think of the OracleAS Web Cache as the primary caching component. It serves cached pages directly to HTTP clients and handles large volumes of HTTP traffic quickly, fitting the requirements of most Web sites. You can use the OracleAS Web Cache to store complete Web pages or partial pages (through use of the JESI tags). Cached pages can be customized, to a certain extent, before being sent to a client, including cookie-replacement and page-fragment concatenation, for example.
It is advisable to use the OracleAS Web Cache as much as possible to reduce the load on the Web application server and back-end database. The caching needs of a large percentage of Web pages can be addressed by the OracleAS Web Cache alone.
As a complement to the OracleAS Web Cache, you can use the Web Object Cache to capture intermediate results of JSP and servlet execution, and subsequently reuse these cached results in other parts of the Java application logic. It is not beneficial to use the Web Object Cache in your Web application unless you are doing a significant amount of post-processing on cached objects between the time they are cached and the time they are served to a client.
In comparison to the Oracle Application Server Java Object Cache, the Web Object Cache makes it much easier to store and maintain partial execution results in dynamic Web pages. The Java Object Cache, being a pure object-based framework for any general Java application, is not aware of the HTTP environment in which it may be embedded. For example, it does not directly depend on HTTP cookies or sessions. When you directly use the Java Object Cache within a Web application, you are responsible for creating any necessary interfacing. The Java Object Cache does not provide a way to specify maintenance policies declaratively.
OC4J supplies two tag libraries for use with OracleAS caching features:
This section summarizes those libraries.
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 in a JSP environment.
Table 1-10 summarizes the JESI tag library. See "Oracle JESI Tag Descriptions" for more information.
The OC4J Web Object Cache is a mechanism that allows Web applications written in Java to capture, store, reuse, post-process, and maintain the partial and intermediate results generated by a dynamic Web page, such as a JSP page or servlet. For programming interfaces, it provides a tag library (for use in JSP pages) and a Java API (for use in servlets).
Table 1-11 summarizes the Web Object Cache tag library. See "Web Object Cache Tag Descriptions" for more information.
With Oracle9iAS release 2 (9.0.3), the OC4J JSP product supports the JavaServer Pages Standard Tag Library (JSTL), as specified in the Sun Microsystems JavaServer Pages Standard Tag Library, Version 1.0 specification. This section provides an overview of JSTL features and OC4J support, covering the following topics:
As of the OC4J 9.0.3 implementation, JSTL is not yet directly included with the OC4J product. You can download the reference implementation from:
http://jakarta.apache.org/builds/jakarta-taglibs/releases/standard/
For information about using this JSTL reference implementation with the OC4J demo applications, refer to the JSP FAQ document, available through:
http://otn.oracle.com/tech/java/oc4j
For complete information about JSTL, refer to the specification at the following location:
http://www.jcp.org/aboutJava/communityprocess/first/jsr052/index.html
JSTL is intended as a convenience for JSP page authors who are not familiar or not comfortable with scripting languages such as Java. Historically, scriptlets have been used in JSP pages to process dynamic data. With JSTL, the intent is for JSTL tag usage to replace the need for scriptlets.
Readers who have used previous versions of the OC4J JSP product will recognize this as similar to the goals of the Oracle JavaServer Pages Markup Language (JML) tag library. While the JML tag library is still supported, use of the standard JSTL is encouraged. Also see "JSTL in Oracle9iAS Release 2: Usage Notes and Future Considerations".
Key JSTL features include the following:
The expression language further simplifies the code required to access and manipulate application data, making it possible to avoid request-time expressions as well as scriptlets. See the next section, "Summary of JSTL Expression Language".
(The term "i18n" refers to an internationalization standard.)
Tag support is broken into four JSTL sublibraries according to the preceding functional areas. Table 1-12 shows the standard TLD URI and prefix for each sublibrary.
See "Overview of JSTL Tags and Additional Features" for more information.
The JSTL expression language makes use of the fact that JSP scoped attributes and request parameters are the preferred vehicles for passing information to and from JSP pages. By using the JSTL expression language, you can avoid having to use JSP scriptlets and request-time expressions.
In JSTL 1.0, the expression language can be used only in JSTL tag attribute values.
As an example, consider the following use of the JSTL c:if tag to pick out steel-making companies from a company list:
<c:if test="${company.industry == 'steel'}">
...
</c:if>
The rest of this section summarizes JSTL expression language syntax and documents how to enable JSTL expression language evaluation in your OC4J JSP applications.
This following list offers a brief summary of key syntax features of the JSTL expression language. This is followed by a few simple examples.
The JSTL expression language is invoked through ${expression} syntax. The most basic semantic is that invocation for a named variable ${foo} yields the same result as the method call PageContext.findAttribute(foo).
To access data within JavaBeans and within collections such as lists, maps, and arrays, the expression language supports the "." and "[]" constructs. The "." construct allows access to properties whose names are standard Java identifiers. The "[]" construct is for more generalized access, but for valid Java identifiers is equivalent to the "." construct. The expressions foo.bar and foo["bar"] yield the same result.
The expression language supports the relational operators == (or eq), != (or ne), < (or lt), > (or gt), <= (or le), >= (or ge).
The expression language supports the arithmetic operators +, -, *, / (or div), % (or mod, for remainder or modulo).
The expression language supports the logical operators && (or and), || (or or), ! (or not), empty.
The following example shows fairly basic invocations of the expression language, including the relational "<=" (less than or equal to) operator.
<c:if test="${auto.price <= customer.priceLimit}">
The <c:out value="${auto.makemodel}"/> is in your price range.
</c:if>
The following example, from the Sun Microsystems JavaServer Pages Standard Tag Library, Version 1.0 specification, shows use of the "." and "[]" constructs.
<%-- "productDir" is a Map object containing the description of
products, "preferences" is a Map object containing the
preferences of a user --%>
product:
<c:out value="${productDir[product.custId]}"/>
shipping preference:
<c:out value="${user.preferences['shipping']}"/>
JSTL offers the following implicit objects:
pageScope--Allows access to page-scope variables.
requestScope--Allows access to request-scope variables.
sessionScope--Allows access to session-scope variables.
applicationScope--Allows access to application-scope variables.
pageContext--Allows access to all properties of the page context of a JSP page.
param--This is a Java Map object where param["foo"] returns the first string value associated with the request parameter foo.
paramValues--paramValues["foo"] returns an array of all string values associated with request parameter foo.
header--Similarly to using param, you can use this to access the first string value associated with a request header.
headerValues--Similarly to using paramValues, you can use this to access all string values associated with a request header.
initParam--Allows access to context initialization parameters.
cookie--Allows access to cookies received in the request.
The expression language also offers the following features:
See the JSTL 1.0 specification for information.
This section provides a summary of JSTL tags and discusses some additional JSTL features. The following topics are covered:
JSTL tags make data available through JSP scoped attributes, referred to as scoped variables, which are used in place of scripting variables. JSTL tags that can make data available in this way have var and scope among their attributes, used as follows:
var--Specify the variable that is to be exposed.
scope--Specify the scope of the variable, either page (default), request, session, or application.
The scope attribute would not be relevant for NESTED variables (which would always have page scope), but variables in the JSTL are AT_END (available from the end-tag to the end of the page).
The following example uses the core library iterator action tag forEach and expression language support tag out to expose the current item of an employees collection:
<c:forEach var="employee" items="${customers}">
The current employee is <c:out value="${customer}"/>
</c:forEach>
JSTL includes functionality to dynamically override JSP configuration data for a particular scope, through a scoped variable. You can accomplish this using functionality of the javax.servlet.jsp.jstl.core.Config class.
According to the JSP 1.2 specification, all scopes (page, request, session, and application) that exist within a JSP page context should together form a single namespace; that is, the name of a scoped variable should be unique across execution of a page.
The Config class has functionality to transparently manipulate configuration parameter names to produce the effect that each scope has its own namespace. Effectively, this enables you to set a configuration parameter for a particular scope only.
See the JSTL 1.0 specification for information.
Table 1-13 summarizes the JSTL tags, organized into functional groupings. The JSTL standard tag prefix is noted for each group.
|
Note: JSTL tags for XML processing are based on XPath (XML Path), a W3C recommendation. XPath provides a concise notation for specifying and selecting parts of an XML document. Refer to the following Web site for information: http://www.w3.org/TR/xpath |
Be aware off the following considerations:
ojsp/jstl demos in your OC4J installation for examples of JSTL usage. Also check the Oracle9iAS release 2 (9.0.3) release notes for system property settings that are required for some of the demos.
A number of other Oracle Application Server components provide JSP tag libraries. This section summarizes the following libraries:
The Oracle tag libraries introduced in this section are JSP standards-compliant.
The following discussion assumes some prior knowledge of the underlying components.
Oracle9i JDeveloper provides a set of custom tags known as Business Components for Java (BC4J) data tags. BC4J data tags provide a simple tag-based approach for interaction with business component data sources. The tags provide complete access to business components and allow viewing, editing, and full DML control.
Custom data tags allow for simplified interaction with Business Components for Java data sources. The tag-based approach to building JSP applications with business components does not require extensive Java programming and is very much like coding an HTML page.
Table 1-14 summarizes the BC4J tag library. The typical tag prefix is jbo.
For more information, refer to the Oracle9i JDeveloper online help.
Oracle9i JDeveloper provides a set of custom tags known as User Interface Extension (UIX) tags. The tags invoke UIX controls, generating the HTML to render tabs, buttons, tables, headers, and other layout and navigational components that implement the Oracle browser look and feel.
The tags are included on several palette pages: UIX Page, UIX Layout, UIX Table, UIX Form, UIX Border Layout, and BC4J UIX. These support page layout, table layout, form layout, border layout, and data-binding to a business components project.
Table 1-15 summarizes the UIX tag library. The typical tag prefix is uix.
For more information, refer to the Oracle9i JDeveloper online help.
UIX JSP pages can include both BC4J data tags and BC4J UIX convenience tags that simplify the presentation of data.
The BC4J UIX convenience tags rely on an ApplicationModule data tag to get the data source from the BC4J application module. In addition to the BC4J UIX tags listed here, you can use the (non-UIX) BC4J tags in UIX JSP pages.
Table 1-16 summarizes the BC4J/UIX tags. The typical tag prefix is bc4juix.
For more information, refer to the Oracle9i JDeveloper online help.
Oracle9i Reports tags integrate with data model objects that are used to create Oracle reports. The Reports custom tags allow you to quickly add report blocks and graphs to existing JSP files. These tags can be used as templates to enable you to build and insert your own data-driven Java component into a Reports HTML page.
An example of a custom JSP tag is the 3D Graphics charting component. Using a custom JSP tag, you can pass Reports data to the 3D application server, which creates an image of the chart. The custom JSP tag then returns HTML to reference the created image.
The report and objects tags, respectively, delimit and define the report block. Inside these tags, other custom tags define the content and the look and feel of the report data.
Table 1-17 summarizes the Reports tags. The typical tag prefix is rw.
For more information, refer to the Oracle9i Reports Developer online help, under Reference/JSP Tags. You can also find more information about Reports on the Oracle Technology Network:
http://otn.oracle.com/products/reports/content.html
Developers of location-based applications need specialized services for the following:
The OracleAS Wireless location application components are a set of APIs for performing geocoding, providing driving directions, and looking up business directories. Service proxies are included that map existing important providers to the APIs, and additional providers are expected to be accommodated in the future.
For JSP developers, a tag library is provided, as summarized in Table 1-18. The typical tag prefix is loc.
For more information, refer to the Oracle Application Server Wireless Developer's Guide 10g.
OracleAS Ultra Search provides a custom tag library for use by developers in incorporating content search functionality into JSP applications. The library includes the following functionality:
The tag library is summarized in Table 1-19. The typical tag prefix is US.
For more information, see the Oracle Ultra Search User's Guide. Alternatively, refer to the Ultra Search online documentation, under Ultra Search JSP Tag Library.
With OracleAS Portal, developers can accomplish the following:
The OracleAS Portal tag library provides further convenience for developers building customizable Internet portals. A developer can create internal JSP pages, which are stored inside the Portal database and downloaded when the portal is executed, or external JSP pages, which are stored in the file system, or some combination.
The tag library is summarized in Table 1-20. The typical tag prefix is portal.
For more information, refer to the document Oracle9i Application Server Portal: Adding JSPs, available through the Oracle Technology Network:
http://otn.oracle.com