![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e1068. Saving and Emitting HTML Fragments Using JSTL in a JSP PageWhen saving text with the special characters<>'"& , the special
characters are save as is; there is no translation that takes
place. However, when emitting text with <c:out> , these special
characters are translated to the equivalent XML entities. In
particular, < becomes < , > becomes > , '
becomes ' , " becomes " , and & becomes
& . This means that a value such as <b> will be emitted
as <b> and therefore not be interpreted as the HTML b
tag.
To prevent this translation, the <%-- Declare the core library --%> <%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> <%-- Save data with html tags --%> <c:set var="msg" value="hi <b>John</b>!" scope="page" /> <%-- Show the value after translating special characters --%> <c:out value='${msg}' /> <%-- Show the value without translating special characters --%> <c:out value='${msg}' escapeXml="false" />
e1065. Enabling the JSTL Expression Language in a JSP Page e1066. Getting a Request Parameter Using JSTL in a JSP Page e1067. Saving Data Using JSTL in a JSP Page e1069. Conditionally Generating Output Using JSTL in a JSP Page © 2002 Addison-Wesley. |