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 " &lt;

" and all ">" with " &gt;

". 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

0


a source to share


4 answers


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

+1


a source


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 :-)

+1


a source


there is an escapeXml attribute on the c: out tag that is set to true by default, set it to false and no escaping occurs, i.e. your HTML will be output as it is in the browser.

0


a source


<c:out value="${data}"/>

outputs HTML characters, but ${data}

not. Have a look at this related question .

0


a source







All Articles