Escape Characters

Because certain character sequences 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 being 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.

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"

Get JavaServer Pages, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.