I would like to escape characters in JSP pages. Which is more suitable, escapeXml
or escapeHtml
?
I would like to escape characters in JSP pages. Which is more suitable, escapeXml
or escapeHtml
?
They're designed for different purposes, HTML has lots of entities that XML doesn't. XML only has 5 escapes:
< represents "<"
> represents ">"
& represents "&"
' represents '
" represents "
While HTML has loads - think of
©
etc. These HTML codes aren't valid in XML unless you include a definition in the header. The numeric codes (like ©
for the copyright symbol) are valid in both.