在thymeleaf中使用th:text添加HTML标签 [英] Adding HTML tags using th:text in thymeleaf

查看:896
本文介绍了在thymeleaf中使用th:text添加HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将HTML标签添加到th:text中,以使标签变得可见?

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

例如:

名为htmlcode的视图变量被注入了值

A view variable called htmlcode gets injected with the value

<b>bla</b>

视图本身看起来像

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

现在我希望结果为

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

推荐答案

我能够通过使用th:utext而不是th:text来解决此问题.这样,HTML标记将以不转义的方式添加.显然,必须谨慎使用,以防止XSS攻击.

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.

这篇关于在thymeleaf中使用th:text添加HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆