我有一个带有 jsp 页面的 webmvc 应用程序作为 View 。
这是我的一种映射方法:
@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 的部分:
<body>
<h1><c:out value="${title}"/></h1>
<hr>
<h2>Description</h2>
<c:out value="${description}"/>
</body>
如您所见,我试图将描述发送到 jsp-attribute ${description}
.
这里的问题在于该描述。它有 html 标签。例如
<p><strong>Responsibilities:</strong></p>
渲染后我得到了一个非常奇怪的 html 页面,其中包含带有所有标签的描述 :(
我该如何解决?
最佳答案
您传递 html 的方式与传递文本的方式相同。您只需要 jtsl 代码不使用 escapeXml="false"指令转义 html。
例如:
<c:out value="${fn:replace(row.entryText, newLineChar, '<br>')}" escapeXml="false" />
关于html - 如何在 Spring MVC 中将 HTML 文本发送到模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33808110/