Problem with HTML output in JSP
I have some code that generates some HTML, but when I try to output this content to jsp, all '<' are replaced with " <
" and all ">" with " >
". Here's a snippet that gives the result:
<c:out value="${data}"/>
Can someone explain the reason for the character change and how it can be avoided?
PS: I tried the escapeXml = 'false' property of the tag <c:out/>
, nothing is displayed.
Thank you Natasha
What do you want to create the generated HTML, do you want it to be the markup used by the browser, or do you want it to appear on the last page, for example, as a sample code visible to the user? Without escapeXml = 'false', it will be output to the browser as HTML and interpreted along with all other markup. With escapeXml = 'true' it will be turned into escaped markup which is rendered to the end user. So it all depends on what you are trying to do.
If you want to have <and> characters visible to the end user, then they should appear as & lt; lt; and? in the markup.
Nick
a source to share
The out tag behaves as it should - if you want to output the value of a letter, you can directly insert the EL express $ {data} into your text. That is, instead of
Some content <c:out value="${data}"/> some more content
would you use
Some content ${data} some more content
in your JSP.
Before you get mad at c: out, please consider that the result is often what the user put there - potentially with some unwanted code. Imagine using $ {data} in StackOverflow instead of (C # version) c: out :-)
a source to share
<c:out value="${data}"/>
outputs HTML characters, but ${data}
not. Have a look at this related question .
a source to share