Java Reference
In-Depth Information
Table 19.2 New XML syntax for JSP constructs
Standard format
New HTML format
<% code %>
<jsp:scriptlet> code </jsp:scriptlet>
<%! code %>
<jsp:declaration> code </jsp:declaration>
<%= expr %>
<jsp:expression> expr </jsp:expression>
19.3.5
But what about that new syntax? It's an XML-conformant syntax, and it's the
syntax for all the newer features added to JSP. In fact, even the old JSP
syntax, the statements that we've discussed, have an alternative new syntax
(Table 19.2). Prior to JSP 2.0, that syntax was reserved for JSP that produce
XML rather than HTML. (That's a whole other can of worms that we won't
open now.) Now, as of JSP 2.0, both forms can be used, if your Web server is
JSP 2.0 compliant.
You can see that the old syntax is more compact and less distracting than
the large tags. We suspect that means the old syntax is likely to continue to be
used for a long time yet. 1
This new syntax is also used for the last two parts of JSP that we will cover,
useBean and tag libraries.
New Syntax
19.3.6
For those who really want to avoid doing any Java coding inside of a JSP, there
is additional syntax that will provide for a lot of capability but without having
to explicitly write any Java statements. Instead, you write a lot of arcane JSP
directives, as we'll show you in just a bit. Is this any better? In some ways yes,
but in other ways, no, it's just different syntax.
What we'll be able to do with this additional syntax is:
JavaBeans in JSP
1. Instantiate a Java class and specify how long it should be kept around
2. Get values from this class
3. Set values in this class
1. The newer XML-style syntax would be useful if your JSP are generated by an XSLT
stylesheet or are validated against a DTD, both topics being beyond the scope of our discussion.
Search WWH ::




Custom Search