Oracle JSP Global Includes

Nel documento Oracle9AS Containers for J2EE (pagine 137-141)

In Oracle9iAS 9.0.2, the OC4J JSP container introduces a feature called global includes. You can use this feature to specify one or more files to statically include into JSP pages in (or under) a specified directory, through virtual JSP include directives. During translation, the JSP container looks for a configuration file, /WEB-INF/ojsp-global-include.xml, that specifies the included files and the directories for the pages.

This enhancement is particularly convenient for migrating applications that used globals.jsa or translate_params functionality in previous Oracle JSP releases.

Globally included files can be used for the following, for example:

global bean declarations (formerly supported through globals.jsa)

common page headers or footers

translate_params equivalent code (typically for a JServ environment) The ojsp-global-include.xml File

The ojsp-global-include.xml file specifies the names of files to include, whether they should be included at the tops or bottoms of JSP pages, and the locations of JSP pages to which the global includes should apply. This section describes the elements of ojsp-global-include.xml.

Important: Implementation details, such as the location of generated output files and use of "_" in output file names, are subject to change in future releases.

<ojsp-global-include>

This is the root element of the ojsp-global-include.xml file. It has no attributes.

Subelements:

<include>

<include ... >

Use this subelement of <ojsp-global-include> to specify a file to be included, and whether it should be included at the top or bottom of JSP pages.

Subelements:

<into>

Attributes:

file: Specify the file to be included, such as "/header.html" or

"/WEB-INF/globalbeandeclarations.jsph". The file name setting must start with a slash ("/"). In other words, it must be context-relative, not

page-relative.

position: Specify whether the file is to be included at the top or bottom of JSP pages. Supported values are "top" (default) and "bottom".

<into ... >

Use this subelement of <include> to specify a location (a directory, and possibly subdirectories) of JSP pages into which the specified file is to be included. This element has no subelements.

Attributes:

directory: Specify a directory. Any JSP pages in this directory, and optionally its subdirectories, will statically include the file specified in the file attribute of the <include> element. The directory setting must start with a slash ("/"), such as "/dir1". The setting can also include a slash after the directory name, such as "/dir1/", or a slash will be appended internally during translation.

subdir: Use this to specify whether JSP pages in all subdirectories of the directory should also have the file statically include. Supported values are

"true" (default) and "false".

Functionality of the JSP Translator

Global Include Examples

This section provides examples of global includes.

Example: Header/Footer Assume the following ojsp-global-include.xml file:

<?xml version="1.0" standalone=’yes’?>

<!DOCTYPE ojsp-global-include SYSTEM ’ojsp-global-include.dtd’>

<ojsp-global-include>

<include file="/header.html">

<into directory="/dir1" />

</include>

<include file="/footer1.html" position="bottom">

<into directory="/dir1" subdir="false" />

<into directory="/dir1/part1/" subdir="false" />

</include>

<include file="/footer2.html" position="bottom">

<into directory="/dir1/part2/" subdir="false" />

</include>

</ojsp-global-include>

This example accomplishes three objectives:

The header.html file is included at the top of any JSP page in or under the dir1 directory. The result would be the same as if each .jsp file in or under this directory had the following include directive at the top of the page:

<%@ include file="/header.html" %>

The footer1.html file is included at the bottom of any JSP page in the dir1 directory or its part1 subdirectory. The result would be the same as if each .jsp file in those directories had the following include directive at the bottom of the page:

<%@ include file="/footer1.html" %>

The footer2.html file is included at the bottom of any JSP page in the part2 subdirectory of dir1. The result would be the same as if each .jsp file in that directory had the following include directive at the bottom of the page:

<%@ include file="/footer2.html" %>

Example: translate_params Equivalent Code Assume the following ojsp-global-include.xml file:

<?xml version="1.0" standalone=’yes’?>

<!DOCTYPE ojsp-global-include SYSTEM ’ojsp-global-include.dtd’>

<ojsp-global-include>

<include file="/WEB-INF/nls/params.jsf">

<into directory="/" />

</include>

</ojsp-global-include>

And assume params.jsf contains the following:

<% request.setCharacterEncoding(response.getCharacterEncoding(); %>

The params.jsf file (essentially, the setCharacterEncoding() method call) is included at the top of any JSP page in or under the application root directory. In other words, it is included in any JSP page in the application. The result would be the same as if each .jsp file in or under this directory had the following include directive at the top of the page:

<%@ include file="/WEB-INF/nls/parms.jsf" %>

Also see "Migration Away from translate_params" on page B-27.

Note: If multiple header or multiple footer files are included into a single JSP page, the order of inclusion is according to the order of

<include> elements in the ojsp-global-include.xml file.

Nel documento Oracle9AS Containers for J2EE (pagine 137-141)