【问题标题】:Prevent Scalatra from escaping text in html page防止 Scalatra 转义 html 页面中的文本
【发布时间】:2015-08-27 07:34:15
【问题描述】:

我有一个如下模板:

    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 )&lt;p/&gt;
381 iphone ( 2015-05-01  Texas)&lt;p/&gt;
259 iphone ( 2015-05-01  NY)&lt;p/&gt;
148 iphone ( 2015-05-01  Tx)&lt;p/&gt;
131 iphone ( 2015-05-01  CA)&lt;p/&gt;
129 android ( 2015-05-01  TX)&lt;p/&gt;

如何指示scalatra“不理会文本”并将其按原样发送到浏览器?

更新请注意,上面的代码在 DisplayPage 内 - 这显然不允许宏/标记。我需要了解为什么示例程序甚至使用 displayPage - 以及更好的替代方案。

【问题讨论】:

    标签: scala scalatra


    【解决方案1】:

    您可以在全局范围内进行:

    <% escapeMarkup = false %>
    

    或者换行:

    some text
    ${unescape(outMsg)}
    

    【讨论】:

    • 好的,我正在尝试。
    • 我已更新 OP:发送到 displayPage 的代码不能包含宏扩展。我需要在这里处理流程:示例程序确实使用了 displayPage 但后来它坏了。在进行一些自我教育后将再次更新 OP。
    【解决方案2】:

    URLEnocding 是由于 xml 节点而发生的,而不是特定于 scalatra。但是,在 scalatra 将内容返回给请求者之前,我没有发现如何撤消编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      • 2021-09-10
      • 2012-02-13
      • 2011-12-08
      • 1970-01-01
      相关资源
      最近更新 更多