Yinan
Yinan

Reputation: 2786

In JSP, how to output "<br/>"

I have a string var in my Struts2 action, like this:

String tmp = "<br/>";

I want to print it out to the html page as HTML tag by JSP, like this:

<s:property value="tmp"/>

But, in the html page, the < and > was translated to &lt; and &gt; which i don't want to.

So how should I do this?

Upvotes: 2

Views: 5566

Answers (3)

Nicola Baldissin
Nicola Baldissin

Reputation: 94

You can do it just using OGNL:

${tmp}

For more information visit the docs page

Upvotes: 0

skaffman
skaffman

Reputation: 403491

<s:property> has an escape attribute which determines if the value is HTML-escaped. The default is true, so that's why your <br/> is being escaped.

So you can do something like this:

<s:property value="tmp" escape="false"/>

Upvotes: 9

Nathan Hughes
Nathan Hughes

Reputation: 96394

If you use JSTL then the c:out tag has an escapeXml attribute you can set to false.

Upvotes: 1

Related Questions