htmlstruts2escapinghtml-escape

How to display HTML markup content from database record to browser properly in Struts 2?


I have a simple text stored in the database record: Hello wrapped in an h1 tag.

When I print this record in the JSP with the <s:property /> tag, it displays:

<h1>Hello</h1>

While I want it to be displayed like:

Hello

How can I get the interpreted value, instead of the source value ?


Solution

  • You need to set the escapeHtml attribute of the <s:property/> tag to false because, for security reasons, it is true by default:

    <s:property value="myVar" escapeHtml="false" />
    

    Read more on the docs.