3

How can I add HTML tags into a th:text so the tags become visual?

An example of this would be the following:

A view variable called htmlcode gets injected with the value

<b>bla</b>

The view itself looks like

<div th:text="*{htmlcode}"><p>defaultcode</p></div>

Now I want the result to be something like

<div><b>bla</b></div>

1 Answer 1

9

I was able to solve this issue by using th:utext instead of th:text. This way, the HTML tags are added unescaped. Obviously, this has to be used with caution, to prevent XSS attacks.

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

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.