Show HTML in JSP (don't โ€œrenderโ€ HTML)

I have a JSP page that accepts SQL queries, executes them, and then returns the results in a table. Some of the results sometimes have HTML tags in them, i.e. the result is returned:

This is the returned result! I have <br> and <hr> tags!

When it is transmitted through the code to process the return and puts it into the table, he actually "displays" tag <br>and <hr>as HTML, but I want him to just display the actual <br>and <hr>.

Returns are currently being printed using <% = colvalue%>

How can i do this?

+3
source share
5 answers

JSTL, <c:out> , .

.

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<c:out value="${value}"/>

escapeXml el taglib

 <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"  %>
 ${fn:escapeXml(someVarWithHtmlInIt)}
+4

I have &lt;br&gt; and &lt;hr&gt; tags!

+1
source

You can use the JSTL tag. It has an escapeXML parameter that will do what you want to do.

0
source

In PHP you would use htmlentities and htmlspecialchars

-2
source

Source: https://habr.com/ru/post/1716524/


All Articles