Jakarta Project: APPLICATION JSP Tag Library
Version 1.0
Table of Contents
Overview
Requirements
Configuration
Tag Summary
Tag Reference
Examples
Javadocs
Revision History
Overview
The APPLICATION custom tag library contains tags which can be used to
access information contained in the ServletContext for a web application.
Tags are provided to access information in "application"-scoped attributes and web application initialization parameters, which are defined in the "/WEB-INF/web.xml" file.
Requirements
This custom tag library requires no software other than a servlet container
that supports the JavaServer Pages Specification, version 1.2.
The tag library also works in some JSP version 1.1 servlet containers, such as Tomcat, but not in others, such as Weblogic. The tags in this tag library are designed according to the JSP 1.2 specification, which makes this requirement of the <jsp:getProperty ... /> tag:
-
The value of the name attribute in jsp:setProperty and jsp:getProperty will refer to an object that is obtained from the pageContext object through its findAttribute() method.
The JSP 1.1 specification does not require this behaviour, and while Tomcat happens to support it, Weblogic does not. Note that it is fairly straightforward to write a custom tag that emulates this behaviour for Weblogic users. Sample source code for such a tag can be found here.
Configuration
Follow these steps to configure your web application with this tag library:
To use the tags from this library in your JSP pages, add the following
directive at the top of each page:
<%@ taglib uri="http://jakarta.apache.org/taglibs/application-1.0" prefix="app" %>
where "app" is the tag name prefix you wish to use for
tags from this library. You can change this value to any prefix you like.
For the examples below the prefix "app" is used.
Tag Summary
Tag Reference
|
Get the value of a single application attribute. |
|
Tag Body |
Empty |
Script Variable |
No |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
name |
Yes |
No |
Name of application attribute to get. |
|
Properties |
None |
Example |
<%-- Output the value of the application attribute with name "test1" --%>
<app:attribute name="test1"/>
|
|
|
Loop through all application attributes. |
|
Tag Body |
JSP |
Script Variable |
Yes, available only within tag body. |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
id |
Yes |
No |
Script variable id for use with standard
jsp:getProperty tag, JSP version 1.2 (or equivalent, see
Requirements for details)
|
|
Properties |
|
Name |
Get |
Set |
name |
Yes |
No |
Application attribute name. |
value |
Yes |
No |
Application attribute value. |
|
Example |
<%-- Output the name and value of all the application attributes --%>
<app:attributes id="loop">
Name: <jsp:getProperty name="loop" property="name"/>
Value: <jsp:getProperty name="loop" property="value"/>
</app:attributes>
|
|
|
Includes the body of the tag if the application attribute equals the value of the match parameter. |
|
Tag Body |
JSP |
Script Variable |
No |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
name |
Yes |
No |
Name of application attribute. |
value |
No |
No |
If value is set to false the equalsattribute tag includes body
of tag if application attribute does not equal the value of the "match" attribute. |
match |
Yes |
Yes |
String to test for equality. |
ignorecase |
No |
No |
If ignorecase is set to true the comparison between the attribute and the "match" attribute ignores case. |
|
Properties |
None |
Example |
<app:equalsattribute name="test1" match="blah">
The application attribute with name test1 matches the string "blah".
</app:equalsattribute>
<app:equalsattribute name="test1" match="blah" value="false">
The application attribute with name test1 does not match the string "blah".
</app:equalsattribute>
|
|
|
Includes the body of the tag if the application attribute exists. |
|
Tag Body |
JSP |
Script Variable |
No |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
name |
Yes |
No |
Name of application attribute. |
value |
No |
No |
If value is set to false the existsattribute tag includes body
of tag if application attribute does not exist. |
|
Properties |
None |
Example |
<app:existsattribute name="test1">
The application attribute with name test1 exists.
</app:existsattribute>
<app:existsattribute name="test1" value="false">
The application attribute with name test1 does not exist.
</app:existsattribute>
|
|
|
Removes an attribute from the application. |
|
Tag Body |
Empty |
Script Variable |
No |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
name |
Yes |
No |
Name of application attribute to remove. |
|
Properties |
None |
Example |
<%-- Remove the application attribute with name "test1" --%>
<app:removeattribute name="test1"/>
|
|
|
Sets the value of the application attribute to the content of the tag body. |
|
Tag Body |
JSP |
Script Variable |
No |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
name |
Yes |
No |
Name of application attribute to set value for. |
|
Properties |
None |
Example |
<%-- Set the application attribute with name "test1" --%>
<app:setattribute name="test1">Test Value</app:setattribute>
|
|
|
Get the value of a single init parameter. |
|
Tag Body |
Empty |
Script Variable |
No |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
name |
Yes |
No |
Name of init parameter to get. |
|
Properties |
None |
Example |
<%-- Output the value of the init parameter with name "test1" --%>
<app:initparameter name="test1"/>
|
|
|
Loop through all init parameters. |
|
Tag Body |
JSP |
Script Variable |
Yes, available only within tag body. |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
id |
Yes |
No |
Script variable id for use with standard
jsp:getProperty tag, JSP version 1.2 (or equivalent, see
Requirements for details)
|
|
Properties |
|
Name |
Get |
Set |
name |
Yes |
No |
Init parameter name. |
value |
Yes |
No |
Init parameter value. |
|
Example |
<%-- Output the name and value of all the init parameters --%>
<app:initparameters id="loop">
Name: <jsp:getProperty name="loop" property="name"/>
Value: <jsp:getProperty name="loop" property="value"/>
</app:initparameters>
|
|
|
Includes the body of the tag if the initparameter equals the value of the match parameter. |
|
Tag Body |
JSP |
Script Variable |
No |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
name |
Yes |
No |
Name of init parameter. |
value |
No |
No |
If value is set to false the equalsinitparameter tag includes body
of tag if init parameter does not equal the value of the "match" attribute. |
match |
Yes |
Yes |
String to test for equality. |
ignorecase |
No |
No |
If ignorecase is set to true the comparison between the init parameter and the "match" attribute ignores case. |
|
Properties |
None |
Example |
<app:equalsinitparameter name="test1" match="blah">
The init parameter with name test1 matches the string "blah".
</app:equalsinitparameter>
<app:equalsinitparameter name="test1" match="blah" value="false">
The init parameter with name test1 does not match the string "blah".
</app:equalsinitparameter>
|
|
|
Includes the body of the tag if the init parameter exists. |
|
Tag Body |
JSP |
Script Variable |
No |
Restrictions |
None |
Attributes |
|
|
Name |
Required |
Runtime Expression Evaluation |
name |
Yes |
No |
Name of init parameter. |
value |
No |
No |
If value is set to false the existsinitparameter tag includes body
of tag if init parameter does not exist. |
|
Properties |
None |
Example |
<app:existsinitparameter name="test1">
The init parameter with name test1 exists.
</app:existsinitparameter>
<app:existsinitparameter name="test1" value="false">
The init parameter with name test1 does not exist.
</app:existsinitparameter>
|
|
Examples
See the example application application-examples.war for examples of the usage
of the tags from this custom tag library.
Java Docs
Java programmers can view the java class documentation for this tag library
as javadocs.
Revision History
Review the complete revision history of this tag
library.