JSP output string with HTML query

J

June Moore

Hi,
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?

Thanks,
June.
 
T

Tony Morris

June Moore said:
Hi,
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?

Thanks,
June.

Your JSP is correct.
I'm guessing you aren't running the code on a servlet container, but a web
server.
Why you would write code like that I don't know, but then, I've seen some
strange stuff in JSP before.
 
A

Andrew Thompson

I thought at first that 'the above string'
meant you saw this (literally) in the final page..
' said:
Your JSP is correct.
I'm guessing you aren't running the code on a servlet container, but a web
server.

...but Tony's comment made the penny drop.

If the 'bold/underlined' string appeared in an
HTML page it would render as HTML, whereas the
second JSP command '<%=str%>' would vanish completely.

But if your server is neither configured to run
..jsp's, and does not send the content to the
client as an HTML content type, you would see all
the code of the original JSP as written by you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top