我一直使用Lift Web Framework作为REST服务已有一段时间了,但我现在需要将它作为一个独立的工具使用。
<lift:surround with="default" at="content">
<head>
<script data-lift="with-resource-id" src="/test.js" type="text/javascript"></script>
</head>
<h2>Welcome to your project!</h2>
<p><lift:helloWorld.howdy /></p>
</lift:surround>
我有上面非常基本的Lift模板。问题是当我在浏览器中查看它时添加了<?xml>
DOCTYPE并且浏览器默认将资源解释为XML而不是纯HTML。
如何告诉Jetty / Lift我的静态文件是HTML?
答案 0 :(得分:1)
也许添加标题会有帮助吗?
<html>
<head>...
实施例: https://github.com/lift/lift_25_sbt/blob/master/scala_29/lift_basic/src/main/webapp/index.html
通常,您使用一种非常古老的模板方法,使用自定义标记<lift:surround>
,<lift:helloWorld>
等。你从哪里得到的?我建议使用我发布的链接中的新模板样式。
答案 1 :(得分:1)
听起来您可能正在使用XHTML doctype。在Boot.scala
文件中,您可能需要尝试添加:
LiftRules.htmlProperties.default.set((r: Req) =>
new Html5Properties(r.userAgent))
这应该将您的应用设置为使用HTML5,并turn off添加<?xml...
编码标题。
另外,正如@VasyaNovikov所提到的,lift:
前缀标签是一个较旧的构造(尽管很多文档仍然提到它们)。他们仍然有效,但HTML5会有一些问题。建议使用以下任一等效形式:
原件:
<lift:surround with="default" at="content">...</lift:surround>
HTML5:
<span data-lift="surround?with=default;at=content"></span>
<span class="lift:surround?with=default;at=content"></span>
如果您想使用lift:
种类,您会发现最大的问题是在HTML5中标签和属性会转换为小写,因此<lift:helloWorld.howdy />
将被解释为<lift:helloworld.howdy />
},和Lift将找不到该片段。使用<span data-lift="helloWorld.howdy"></span>
可以让您解决这个问题。