Escape Characters
Because certain character sequences are used to represent start and stop tags, you sometimes need to escape a character so the container doesn’t interpret it as part of a special character sequence.
In a scripting element, if you need to use the characters
%> literally, you must escape the greater-than
character with a backslash:
<% String msg = "Literal %\> must be escaped"; %>
To avoid the character sequence <% in template
text to be interpreted as the start of a scripting element, you must
escape the percent sign:
This is template text and <\% is not a start of a scriptlet.
Similarly, the dollar sign that start an EL expression must be escaped in a page where EL evaluation is enabled:
This is template text and \${this is not an EL expression}.In an attribute value, you must use the following escapes:
attr='a value with an escaped \' single quote' attr="a value with an escaped \" double quote" attr="a value with an escaped \\ backslash" attr="a value with an escaped %\> scripting end tag" attr="a value with an escaped <\% scripting start tag" attr="a value with an escaped \$ dollar sign"
As an alternative to escaping quote characters, you can use the
' and "
character entities.
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