防止 Scalatra 转义 html 页面中的文本
Prevent Scalatra from escaping text in html page
我有如下模板:
val outMsg = s"${outMap.mkString("<p/>\n")}"
if (returnMode.equalsIgnoreCase("HTML")) {
response.setContentType("text/html")
displayPage("Keywords Query Results:",
// <p>Query: {jsonObject.get.toString}</p>
<p>Return:
{outMsg}
现在发送到浏览器的内容:
419 iphone ( 2015-05-01 )<p/>
381 iphone ( 2015-05-01 Texas)<p/>
259 iphone ( 2015-05-01 NY)<p/>
148 iphone ( 2015-05-01 Tx)<p/>
131 iphone ( 2015-05-01 CA)<p/>
129 android ( 2015-05-01 TX)<p/>
如何指示 scalatra "leave the text alone" 并将其按原样发送到浏览器?
Update 请注意,上面的代码在 DisplayPage 中 - 这显然不允许 macros/markup。我需要了解为什么示例程序甚至完全使用 displayPage - 以及更好的选择是什么。
您可以在全球范围内进行:
<% escapeMarkup = false %>
或换行表达式:
some text
${unescape(outMsg)}
URLEnocding 是由于 xml 节点而不是 scalatra 特有的。但是,我没有发现如何在 scalatra returns 将内容发送给请求者之前撤消编码。
我有如下模板:
val outMsg = s"${outMap.mkString("<p/>\n")}"
if (returnMode.equalsIgnoreCase("HTML")) {
response.setContentType("text/html")
displayPage("Keywords Query Results:",
// <p>Query: {jsonObject.get.toString}</p>
<p>Return:
{outMsg}
现在发送到浏览器的内容:
419 iphone ( 2015-05-01 )<p/>
381 iphone ( 2015-05-01 Texas)<p/>
259 iphone ( 2015-05-01 NY)<p/>
148 iphone ( 2015-05-01 Tx)<p/>
131 iphone ( 2015-05-01 CA)<p/>
129 android ( 2015-05-01 TX)<p/>
如何指示 scalatra "leave the text alone" 并将其按原样发送到浏览器?
Update 请注意,上面的代码在 DisplayPage 中 - 这显然不允许 macros/markup。我需要了解为什么示例程序甚至完全使用 displayPage - 以及更好的选择是什么。
您可以在全球范围内进行:
<% escapeMarkup = false %>
或换行表达式:
some text
${unescape(outMsg)}
URLEnocding 是由于 xml 节点而不是 scalatra 特有的。但是,我没有发现如何在 scalatra returns 将内容发送给请求者之前撤消编码。