9

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.

2
  • 2
    Deja vu: velocityreviews.com/forums/… (and from 2004, no less...) Commented Feb 22, 2012 at 6:50
  • Yeah I tried that but didnt work..Thats why I am questioning it here Commented Feb 22, 2012 at 6:53

2 Answers 2

16

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Harry, Your escapeXml='false' tip helped me.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.