| 1 |
<!-- |
| 2 |
|
| 3 |
Copyright (c) 1997, 2020 Oracle and/or its affiliates and others. |
| 4 |
All rights reserved. |
| 5 |
Copyright 2004 The Apache Software Foundation |
| 6 |
|
| 7 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 |
you may not use this file except in compliance with the License. |
| 9 |
You may obtain a copy of the License at |
| 10 |
|
| 11 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 12 |
|
| 13 |
Unless required by applicable law or agreed to in writing, software |
| 14 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 15 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 |
See the License for the specific language governing permissions and |
| 17 |
limitations under the License. |
| 18 |
|
| 19 |
--> |
| 20 |
<!-- |
| 21 |
References in this document to JSP refer to the Jakarta Server Pages |
| 22 |
unless otherwise noted. |
| 23 |
--> |
| 24 |
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 25 |
<html> |
| 26 |
<head> |
| 27 |
|
| 28 |
</head> |
| 29 |
<body bgcolor="white"> |
| 30 |
Provides the <code>ELResolver</code> classes that define the |
| 31 |
object resolution rules that must be supported by a JSP container |
| 32 |
with the new unified Expression Language. |
| 33 |
<p> |
| 34 |
References in this document to JSP refer to the Jakarta Server Pages |
| 35 |
unless otherwise noted. |
| 36 |
</p> |
| 37 |
<p> |
| 38 |
The package also defines programmatic access to the old Expression Language |
| 39 |
evaluator (pre JSP 2.1). |
| 40 |
<p> |
| 41 |
<b>Please note |
| 42 |
that as of JSP 2.1, all classes and interfaces that were in package |
| 43 |
<code>jakarta.servlet.jsp.el</code> have been deprecated in favor of the new unified |
| 44 |
Expression Language APIs (<code>jakarta.el</code>). See the Expression Language |
| 45 |
specification document for more details.</b> |
| 46 |
</p> |
| 47 |
<p> |
| 48 |
<b>While a JSP container must still support the deprecated APIs defined |
| 49 |
in <code>jakarta.servlet.jsp.el</code>, developers should only rely on the |
| 50 |
new <code>jakarta.el</code> APIs |
| 51 |
for new development work.</b> |
| 52 |
</p> |
| 53 |
<p> |
| 54 |
Two ELResolver classes have been added in JSP 2.1 to implement |
| 55 |
object resolution rules that must be supported by a JSP container |
| 56 |
with the new unified Expression Language: |
| 57 |
{@link jakarta.servlet.jsp.el.ImplicitObjectELResolver} and |
| 58 |
{@link jakarta.servlet.jsp.el.ScopedAttributeELResolver}. |
| 59 |
</p> |
| 60 |
|
| 61 |
<h2>Documentation on the old and deprecated API</h2> |
| 62 |
|
| 63 |
<p> |
| 64 |
The Jakarta Server Pages 2.0 specification provides a portable |
| 65 |
API for evaluating "EL Expressions". As of JSP 2.0, EL expressions can |
| 66 |
be placed directly in the template text of JSP pages and tag files. |
| 67 |
<p> |
| 68 |
This package contains a number of classes and interfaces that describe |
| 69 |
and define programmatic access to the Expression Language evaluator. |
| 70 |
This API can also be used by an implementation of JSP to evaluate the |
| 71 |
expressions, but other implementations, like open-coding into Java |
| 72 |
bytecodes, are allowed. This package is intended to have no dependencies |
| 73 |
on other portions of the JSP 2.0 specification. |
| 74 |
|
| 75 |
<h3>Expression Evaluator</h3> |
| 76 |
|
| 77 |
Programmatic access to the EL Expression Evaluator is provided |
| 78 |
through the following types: |
| 79 |
|
| 80 |
<ul> |
| 81 |
<li><code>ExpressionEvaluator</code></li> |
| 82 |
<li><code>Expression</code></li> |
| 83 |
<li><code>FunctionMapper</code></li> |
| 84 |
<li><code>VariableResolver</code></li> |
| 85 |
</ul> |
| 86 |
|
| 87 |
<p> An <code>ExpressionEvaluator</code> object can be obtained from a |
| 88 |
JspContext object through the <code>getExpressionEvaluator</code> |
| 89 |
method. An ExpressionEvaluator encapsulates the EL processor. An EL |
| 90 |
expression provided as a String can then be evaluated directly, or it |
| 91 |
can be parsed first into an <code>Expression</code> object. The parse |
| 92 |
step, can be used to factor out the cost of parsing the expression, or |
| 93 |
even the cost of optimizing the implementation.</p> |
| 94 |
|
| 95 |
<p>The parsing of an expression string is done against a target type, |
| 96 |
a default prefix (that applies when a function has no prefix), and |
| 97 |
a <code>FunctionMapper</code>. The <code>FunctionMapper</code> object |
| 98 |
maps a prefix and a local name part into a |
| 99 |
<code>java.lang.reflect.Method</code> object.</p> |
| 100 |
|
| 101 |
<p>The interpretation or evaluation of a parsed expression is done |
| 102 |
using a <code>VariableResolver</code> object. This object resolves |
| 103 |
top level object names into Objects. A <code>VariableResolver</code> |
| 104 |
can be obtained from a <code>JspContext</code> object through the |
| 105 |
<code>getVariableResolver</code> method.</p> |
| 106 |
|
| 107 |
<h3>Exceptions</h3> |
| 108 |
|
| 109 |
<p> |
| 110 |
The <code>ELException</code> exception is used by the expression |
| 111 |
language to denote any exception that may arise during the parsing or |
| 112 |
evaluation of an expression. |
| 113 |
The <code>ELParseException</code> exception is a subclass of |
| 114 |
<code>ELException</code> that corresponds to parsing errors</p> |
| 115 |
|
| 116 |
<p>Parsing errors are conveyed as exceptions to simplify the API. It |
| 117 |
is expected that many JSP containers will use additional mechanisms to |
| 118 |
parse EL expressions and report their errors - a run-time API cannot |
| 119 |
provide accurate line-error numbers without additional machinery.</p> |
| 120 |
|
| 121 |
<h3>Code Fragment</h3> |
| 122 |
|
| 123 |
<p> |
| 124 |
Below is a non-normative code fragment outlining how the APIs can be used.</p> |
| 125 |
|
| 126 |
<pre> |
| 127 |
// Get an instance of an ExpressionEvaluator |
| 128 |
|
| 129 |
|
| 130 |
ExpressionEvaluator ee = myJspContext.getExpressionEvaluator(); |
| 131 |
VariableResolver vr = myJspContext.getVariableResolver(); |
| 132 |
|
| 133 |
FunctionMapper fm; // we don't have a portable implementation yet |
| 134 |
|
| 135 |
// Example of compiling an expression. See [ISSUE-2] |
| 136 |
// Errors detected this way may have higher quality than those |
| 137 |
// found with a simple validate() invocation. |
| 138 |
|
| 139 |
ExpressionCompilation ce; |
| 140 |
|
| 141 |
try { |
| 142 |
ce = ee.prepareExpression(expr, |
| 143 |
targetClass, |
| 144 |
fm, |
| 145 |
null // no prefixes |
| 146 |
); |
| 147 |
} catch (ELParseException e) { |
| 148 |
log (e.getMessage()); |
| 149 |
} |
| 150 |
|
| 151 |
try { |
| 152 |
ce.evaluate(vr); |
| 153 |
} catch (ElException e) { |
| 154 |
log (e); |
| 155 |
} |
| 156 |
</pre> |
| 157 |
|
| 158 |
</body> |
| 159 |
</html> |
| 160 |
|
| 161 |
|