Generating Elements Dynamically
Example 17-10 contains a JSP standard action that you have not seen in previous examples, combined with a couple of actions that are more familiar:
<jsp:element name="${param.element}">
<jsp:attribute name="style">${param.style}</jsp:attribute>
<jsp:body>${param.body}</jsp:body>
</jsp:element>The <jsp:element> action generates a new XML
element in the response with the name specified by the
name attribute. The
<jsp:attribute> and
<jsp:body> elements perform the same
function as in previous chapters—adding an attribute and a body
to the element, respectively. Together, these standard actions allow
you to create any XML element, with any number of attributes and a
body based on the evaluation result of their bodies, while still
keeping the JSP Document as a well-formed XML document. For instance,
if the page in Example 17-10 receives the parameters
element with the value p,
style with the value
font-weight:bold, and body with
the value Hello+World, this element is generated:
<p style="font-weight:bold">Hello World</p>
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access