如何在Spring MVC中将HTML文本发送到Model [英] How to send HTML text to Model in Spring MVC
问题描述
我有一个以jsp-page为视图的webmvc应用程序.
I have webmvc application with jsp-page as a view.
这是我的一种映射方法:
Here one of my mapping methods:
@RequestMapping("vacancy/{id}")
public String showVacancy(@PathVariable String id, Model model) {
Vacancy vacancy = vacancyRepository.findOne(new ObjectId(id));
model.addAttribute("description", vacancy.getDescription());
return "vacancy";
}
这是vacancy.jsp的一部分:
Here the part of vacancy.jsp:
<body>
<h1><c:out value="${title}"/></h1>
<hr>
<h2>Description</h2>
<c:out value="${description}"/>
</body>
如您所见,我试图将描述发送到jsp-attribute ${description}
.
这里的问题就是该描述.它具有html标签.例如
As you can see, I trying to send description to jsp-attribute ${description}
.
The problem here is in that description. It has html-tags. For example
<p><strong>Responsibilities:</strong></p>
渲染后,我得到一个非常奇怪的html页面,其中包含带有所有标签的描述:(
And after rendering I get quite strange html page that includes that description with all tags :(
我该如何解决?
推荐答案
您以与传递文本相同的方式传递html.您只需要jtsl代码即可通过使用escapeXml ="false"指令不对html进行转义.
You pass html the same way you pass text. You just need the jtsl code to not escape the html by using the escapeXml="false" directive.
例如:
<c:out value="${fn:replace(row.entryText, newLineChar, '<br>')}" escapeXml="false" />
这篇关于如何在Spring MVC中将HTML文本发送到Model的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!