JSP output string with HTML?

I would like to print a string on a JSP page. The string contains an HTML tag. How to display HTML version of string in JSP?

eg.

`String str = "<b><u>bold and underlined</u></b>"`; 

In JSP, I use <%=str%>

Instead of displaying the HTML version of the line (in bold and underlining text), the above line is displayed. You can help?

I also tried

  <% out.print(str); %> 

But it didn’t work for me.

+6
source share
2 answers

Better to use JSTL, something like:

 <c:out value="${str}" escapeXml="false"/> 

If str comes in request, then

 <c:out value="${param.str}" escapeXml="false"/> 

Here, escapeXml="false" will indicate that the html / xml tags should be evaluated and not escaped.

+11
source

I don’t know how this helps.

Entering a line in the following form allows you to show the code in the text area ...

  String str = "<textarea><b><u>bold and underlined</u></b></textarea>"; 
+2
source

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


All Articles