JSP.2.12 Tag Attribute Interpretation Semantics


Generally, all custom and standard action attributes and their values either remain uninterpreted by, or have well-defined action-type specific semantics known to, a conforming JSP container. However, there are two exceptions to this general rule: some attribute values represent request-time attribute values and are processed by a conforming JSP container, and the id and scope attributes have special interpretations.

JSP.2.12.1 Request-Time Attribute Values

Action elements (both standard and custom) can define named attributes and associated values. Typically a JSP page treats these values as fixed and immutable, but the JSP 1.1 provides a mechanism to describe a value that is computed at request time.

An attribute value of the form " <%= scriptlet_expr %> " or ' <%= scriptlet_expr % >' denotes a request-time attribute value . The value denoted is that of the scriptlet expression involved. Request-time attribute values can be used only in actions. If there is more than one such attribute in a tag, the expressions are evaluated left to right.

Only attribute values can be denoted in this way (e.g., the name of the attribute is always an explicit name ), and the expression must appear by itself (e.g., multiple expressions and mixing of expressions and string constants are not permitted; instead perform these operations within the expression).

The resulting value of the expression depends upon the expected type of the attribute's value. The type of an action element indicates the valid Java programming language type for each attribute value; the default is java.lang.String .

By default, all attributes have page translation-time semantics. Attempting to specify a scriptlet expression as a value for an attribute that has page translation time semantics is illegal and will result in a fatal translation error. The type of an action element indicates whether a given attribute will accept request-time attribute values.

Most attributes in the actions defined in the JSP 1.1 specification have page translation-time semantics.

The following attributes accept request-time attribute expressions:

  • The value and beanName attributes of jsp:setProperty (JSP.2.13.2)

  • The page attribute of jsp:include (JSP.2.13.4)

  • The page attribute of jsp:forward (JSP.2.13.5)

  • The value attribute of jsp:param (JSP.2.13.6)

JSP.2.12.2 The id Attribute

The id="name" attribute/value tuple in an element has special meaning to a JSP container, both at page translation time and at client request processing time; in particular:

  • The name must be unique within the translation unit, and identifies the particular element in which it appears to the JSP container and page. Duplicate id 's found in the same translation unit shall result in a fatal translation error.

  • In addition, if the action type creates one or more object instances at client request processing time, one of these objects will usually be associated by the JSP container with the named value and can be accessed via that name in various contexts through the pagecontext object described later in this specification. Furthermore, the name is also used to expose a variable (name) in the page's scripting language environment. The scope of this scripting language dependent variable is dependent upon the scoping rules and capabilities of the actual scripting language used in the page. Note that this implies that the name value syntax shall comply with the variable naming syntax rules of the scripting language used in the page.

Chapter JSP.4 provides details for the case where the language attribute is "java."

For example, the <jsp: usebean id=" name " class=" className " .../> action defined later herein uses this mechanism in order to possibly instantiate and subsequently expose the named JavaBeans component to a page at client request processing time.

For example:

 <% { //  introduce a new block  %>     ...     <jsp:useBean id="customer" class="com.myco.Customer" />     <%     /*      *  the tag above creates or obtains the Customer Bean  * reference, associates it with the name "customer" in the      * PageContext, and declares a Java programming language      * variable of the      * same name initialized to the object reference in this      * block's scope.      */     %>     ...     <%= customer.getName(); %>     ...  <% } //  close the  block  %>  <%  //  the variable customer is out of scope now but  //  the object is still valid (and accessible via pageContext)  %> 

JSP.2.12.3 The scope Attribute

The scope="pagerequestsessionapplication" attribute/value tuple is associated with and modifies the behavior of the id attribute described above (it has both translation time and client request processing time semantics). In particular, it describes the namespace, the implicit life cycle of the object reference associated with the name , and the APIs used to access this association, as in Table JSP.2-6.

Table JSP.2-6. Value of the scope Attribute

page

The named object is available from the javax.servlet.jsp.PageContext for the current page.

This reference shall be discarded upon completion of the current request by the page body.

It is illegal to change the instance object associated, such that its runtime type is a subset of the type of the current object previously associated.

request

The named object is available from the current page's ServletRequest object using the getAttribute(name) method. This reference shall be discarded upon completion of the current client request.

It is illegal to change the value of an instance object so associated, such that its runtime type is a subset of the type(s) of the object previously so associated.

session

The named object is available from the current page's HttpSession object (which can in turn be obtained from the ServletRequest object) using the getValue(name) method.

This reference shall be discarded upon invalidation of the current session.

It is illegal to change the value of an instance object so associated, such that its new runtime type is a subset of the type(s) of the object previously so associated.

Note it is a fatal translation error to attempt to use session scope when the JSP page so attempting has declared, via the <%@ page ... %> directive (see Section JSP.2.7.1) that it does not participate in a session .

application

The named object is available from the current page's ServletContext object using the getAttribute(name) method. This reference shall be discarded upon reclamation of the ServletContext .

It is illegal to change the value of an instance object so associated, such that its new runtime type is a subset of the type(s) of the object previously so associated.



Java 2 Platform, Enterprise Edition. Platform and Component Specifications
Java 2 Platform, Enterprise Edition: Platform and Component Specifications
ISBN: 0201704560
EAN: 2147483647
Year: 2000
Pages: 399

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net