Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jsp

struts2

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?

like image 229
Yinan Avatar asked Nov 19 '25 09:11

Yinan


2 Answers

<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"/>
like image 195
skaffman Avatar answered Nov 21 '25 23:11

skaffman


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

like image 35
Nathan Hughes Avatar answered Nov 21 '25 22:11

Nathan Hughes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!