Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSP output string with HTML?

Tags:

html

string

jsp

I would like to output a string in a JSP page. The string contains HTML tag. How do I display the HTML version of the string in JSP?

e.g.

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

In JSP, I use <%=str%>

Instead of displaying the HTML version of the string (with bold and underlining of the text), the above string is displayed. Can you help?

I also tried

                   <% out.print(str); %>

But didnt worked for me.

like image 385
Navdroid Avatar asked Feb 22 '12 06:02

Navdroid


2 Answers

Better to use JSTL, something like:

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

If str is coming in request then

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

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

like image 154
Harry Joy Avatar answered Oct 07 '22 16:10

Harry Joy


don't know weather this helps..

By entering the string in the following manner allows you to show the code in a text area...

 String str = "<textarea><b><u>bold and underlined</u></b></textarea>";  
like image 45
Rangana Sampath Avatar answered Oct 07 '22 14:10

Rangana Sampath