Leon Zhang's Blog
Leon Zhang's Homepage
Leon Zhang is a senior software engineer of Weblogic server's Web
container(servlet/JSP) team. He is the main developer of weblogic
server's JSP compiler. He has big interests in compiling, OS and
security technologies. He also likes playing basketball, climbing
mountains, touring.
WLS 10.X's JSP container's backward compatibility
Posted by lezhang on May 15, 2008 at 10:56 PM | Permalink
| Comments (0)
Abstract
JSP 2.1 imports some new features, and WLS 10.X's JSP compiler could support it
and keep backward compatibility with JSP 2.0 at same time. This article describes
how WLS10.x's JSP compiler attains it.
Introduction
Recently, I found that some users' web
application cannot work well under WLS10.x's because of incorrect definition of
JSP version of their application. This article is trying to introduce more
details to help users to clarify some confusion about this topic.
As we have known, JSP 2.1 specification
imports some new features, e.g. deferred EL expression (#{expression}), more
additional attributes for page and tag directives (deferredSyntaxAllowedAsLiteral,
trimDirectiveWhitespaces), only four implicit packages
imported by JSP compiler (java.lang.*, javax.servlet.*, javax.servlet.jsp.*,
and javax.servlet.http.* are the implicit packages),
additional elements for TLD (deferred-value element), and so on.
But, there are syntax conflicts between JSP
2.1's behavior and JSP20's. For example, deferred EL expression in JSP 2.0's
template text is valid (regarded as normal template text), but it is invalid in
JSP 2.1(Deferred value is only allowed to set to the attributes of tags).
In addition, new attribute of page and tag directive should only be supported
by JSP 2.1.
Check JSP
version
To guarantee that
correct behavior for web applications with different JSP versions is shown,
JSP compiler has to check JSP version of JSP sources to be compiled. If JSP
container finds that the JSP to be compiled is JSP 2.0's application, it will
show old JSP compiler's behavior, and new behavior is shown for JSP2.1's
application. Currently, there are some rules to determine whether a JSP source's
version is JSP 2.0 or JSP 2.1.
Basic rule
The basic rule to
determine whether current JSP compiler is running under JSP 2.1 environment:
if web application's version is 2.5(its web.xml's
version is 2.5), the JSP version is 2.1. In addition, there are additional
detailed rules to define exact behaviors under different scenarios.
Additional rules
Tag/Tagx file's jsp version's
determination is different from jsp/jspx files'. The
former's
should be from tag library's version while the latter should be from webapp version or <jsp:root>'s version attribute.
1. Rules for tag/tagx files:
1) Tag/tagx files' JSP version is from its referred tag library's
version, and <jsp:root>'s
version attribute should be ignored during compiling a tagx
file.
2) A TLD file is
matched to an internal tag library, and a tag/tagx
file directory is also matched to internal created tag library. If a tag/tagx file is referred by both an explicit TLD file and an
internal created implicit tag library, its JSP version is determined by the
matched tag library which is related to the using mode of taglib
directive.
Watch JSP source
clip below:
...
<%@ taglib prefix="tags1" uri="some-uri-link" %>
<%@ taglib prefix="tags2" tagdir="/WEB-INF/tags " %>
<tags1: taga />
<tags2: taga />
...
A TLD file whose uri value is
"some-uri-link" has a tag definition like
below:
<tag-file>
<name>taga </name>
<path>/WEB-INF/tags/taga.tag</path>
</tag-file>
"tags1" is
matched to tag library defined by an explicit TLD file whose <uri> element's value is "some-uri-link".
This tag library is referring to taga.tag file under "WEB-INF/tags".
"tags2"
is matched to an internal implicit tag library for directory "/WEB-INF/tags"
which contains taga.tag.
"taga" is matched to a factual
tag file referred by both tag libraries above.
If these two tag libraries have different JSP
versions, that tag file will have two different JSP versions under these two
scenarios.
By the way, implicit tag library's default
version is 2.0 since this using mode appear since JSP 2.0. For example, If a webapp's version is 2.5, compiling a JSP page referring to
a tag file with #{...0...2} in template should NOT report any error since this tag
file's default JSP version is 2.0 which regards deferred EL expression as
template text.
3) implicit.tld
JSP 2.1 imports a
new feature named "implicit.tld file",
which can be used to define the JSP version of implicit tag library created for
the tag/tagx files directory. If you want to declare
that your tag/tagx file's JSP version is 2.1, you
should put an implicit.tld whose version must be 2.1
into tag/tagx file's directory (By the way, that tag/tagx file should be referred to like "tags2" in
example above).
Lines below copied from JSP 2.1
specification is a reference:
[1]"E.2.5 JSP Version of Tag Files
Clarified how the JSP version of tag files
is determined: Tag files packaged in a JAR file inherit the JSP version from
the referencing TLD. For tag files packaged directly in a web
application, the JSP version defaults to 2.0 and may be configured from the JSP
version of a TLD with the reserved name implicit.tld placed in the same directory as the tag files. The implicit.tld may also be used to configure
the tlib-version of an implicit tag library. "
2. Rules for JSP/JSPX files:
1) Default JSP
version should be from web.xml's webapp
version (2.5 means JSP 2.1, 2.4 means JSP 2.0).
2) <jsp:root>'s version attribute
could overlap previous default JSP version.
3) If main jsp/jspx static included a child jsp/jspx
fragment, compositive whole jsp/jspx's
JSP version is from main jsp/jspx since main jsp's compiling result is not based on the return value of
sub jsp/jspx but the whole compositive
jsp/jspx.
Summarized
behavior for different JSP version
WLS10.x dose not
allow JSP 2.0's web application to apply resources whose JSP version is 2.1.
For example, if some jsp/jspx/tag/tagx file,
whose JSP version is 2.0, is referring to a 2.1 tag/tagx
file, an error will be reported out, vice versa is OK.
More collected
behavior is shown under table below:
| Webapp version |
Scenario
description |
WLS 10.X's JSP
container's expected behavior |
|
2.4
|
JSP page + #{...0...2} template
|
No error, since
it is a valid 2.4 webapp
|
|
tag file using
new features of jsp2.1(e.g. directives' new attributes)
|
Report Error
|
|
JSP doc's <jsp:root>'s version is 2.1
|
Apply <jsp:root>'s version value,
report error if met unsupported features.
|
|
JSP doc's <jsp:root>'s version is 2.1 + JSP 2.1's new attributes
of directive
|
Apply <jsp:root>'s version value,
report error if met unsupported features.
|
|
JSP doc's <jsp:root>'s version is 2.0 + jsp2.1's new
features
|
Report Error
|
|
Main JSP doc's
<jsp:root>'s version is 2.0 or without <jsp:root> + included JSP doc's jsp2.1's new features
|
Report Error
|
|
2.0's JSP is
referring to JSP2.1's tag
|
Report error
|
|
JSP doc's <jsp:root>'s version is 2.0 + set "#{...0...2}"
to a jsp2.1 tag's attribute whose deferred-value is defined as false in TLD
|
Report error
about conflicted JSP version.
|
|
JSP doc's <jsp:root>'s version is 2.0 + set "#{...0...2}"
to a jsp2.1 tag's attribute whose deferred-value is defined as true in TLD
|
Report error
about conflicted JSP version.
|
|
JSP doc's <jsp:root>'s version is 2.0 + set "#{...0...2}"
to a jsp2.0 tag's attribute
|
#{...0...2} will be regarded as string "#{...0...2}"
|
|
2.5
|
JSP doc's <jsp:root>'s version is 2.0 + #{...0...2} template
|
No error
|
|
JSP doc's <jsp:root>'s version is 2.0
|
Apply <jsp:root>'s version value,
Report error if
met jsp2.1's features
|
|
Main JSP doc's
<jsp:root>'s version is 2.0 or without <jsp:root> + included jsp doc's
jsp2.1
|
Ignore included
files' <jsp:root>'s
value, and report error when jsp2.1's new features are met in included file.
|
|
JSP doc's <jsp:root>'s version is 2.0 + referring to tag 2.1
|
Report Error
|
|
JSP doc's <jsp:root>'s version is 2.0 + set "#{...0...2}"
to a jsp2.1 tag's attribute whose deferred-value is defined as false in TLD
|
Report error
about conflicted JSP version.
|
|
A JSP page is
referring to tag file with template #{...0...2}
|
No Error, since
tag file's default JSP version is 2.0.
|
|
JSP doc's <jsp:root>'s version is 2.0 + set "#{...0...2}"
to a jsp2.0 tag's attribute
|
#{...0...2} will be regarded as string "#{...0...2}"
|
Other stuff
about JSP compiler's backward compatibility
Refer to edocs:
http://e-docs.bea.com/wls/docs100/webapp/weblogic_xml.html#wp1075210
Conclusion
WLS 10.x's JSP compiler
could show correct behavior according to web application's JSP version. For old
web application, JSP compiler show same behavior as old JSP compiler. JSP 2.1's
features are also supported by JSP compiler at same time.
Reference
[1] http://jcp.org/en/jsr/detail?id=245
 |