使用 Velocity 显示解析后的 HTML 输出
我有一个速度模板...
它包含以下标签:
#field('itemname')
“itemname”变量包含此:
<i>Some</i> <b>Example Title</b>
输出页面的源有此:
一些 示例标题
因此,用户看到的是实际的 HTML 标签:
<i>Some</i> <b>Example Title</b>
我希望他们看到的是:
Some 示例标题
我哪里出错了?
i have a velocity template...
It contains the following tag:
#field('itemname')
The "itemname" variable contains this:
<i>Some</i> <b>Example Title</b>
The source of the outputted page has this:
<i>Some</i>
<b>Example Title</b>
So, the user sees the actual HTML tags:
<i>Some</i> <b>Example Title</b>
What I want them to see is:
Some Example Title
Where am I going wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我从您的代码片段中看到,问题不在于速度模板,而在于您的用户接收的 HTTP 响应的 mime 类型编码。它应该是“text/html”,但我怀疑它是其他东西,因此,浏览器显示标签而不是“渲染”它们所代表的内容。
当然,我不知道你的是什么
macro does, so the problem might be something else, e.g. that macro might generate a wrapping PRE tag or a Text Area, and this might be the cause you why the those B and I tags are displayed as they are instead of being rendered.
If I see right from your snippets, the problem is not with the velocity template, but with the mime type encoding of the HTTP Response your user is receiving. It should be "text/html", but I suspect it's something else, and so, the browser is showing the tags instead of "rendering" them to what they represent.
Of course, I don't know what your
macro does, so the problem might be something else, e.g. that macro might generate a wrapping PRE tag or a Text Area, and this might be the cause you why the those B and I tags are displayed as they are instead of being rendered.