html - Play Framework : how to render static HTML pages with static js and css?

标签 html css playframework

我正在尝试找出一种方法来呈现或路由到 Play 公共(public)文件夹中托管的一些静态 Web 应用程序。我的元素结构如下:

myapp
  + app
  + conf
  + modules
  + public
      |   + webapp1
      |        + css
      |        + images
      |        + index.html
      |   + webapp2
      |        + css
      |        + images
      |        + index.html
  + ...

我想渲染 webapp1 和 webapp2。每个网络应用程序中的 index.html 将使用每个网络应用程序的 css 文件夹中的 css 文件。

我尝试像这样使用路由并在 Controller 中使用重定向来呈现静态 html 页面:

Redirect("/webapp1/").withCookies(Cookie("token", "")).bakeCookies()
Redirect("/webapp2/").withCookies(Cookie("token", "")).bakeCookies()
GET  /webapp1/  controllers.Assets.at(path="/public/webapp1", file="index.html")
GET  /webapp1/*file   controllers.Assets.at(path="/public/webapp1", file)
GET  /webapp2/  controllers.Assets.at(path="/public/webapp2", file="index.html")
GET  /webapp2/*file   controllers.Assets.at(path="/public/webapp2", file)

index.html 将被正确路由和呈现。但是,文件夹中的 css 和图像未正确加载。 index.html 使用相对路径加载它们。然后以某种方式在顶层加载 css 和图像,例如 localhost/css/css1,而不是 localhost/webapp1/css/css1。

非常感谢您的建议。

比尔

最佳答案

尝试使用下面的路由来加载 css 和 javascript。

加载CSS:

/css/*file controllers.Assets.at(path="/public/css", file)

用于加载 Java 脚本:

/javascript/*file controllers.Assets.at(path="/public/css", file)

关于html - Play Framework : how to render static HTML pages with static js and css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53475514/

相关文章:

html - HbbTV 编程

html - ng-bind 不应该也适用于输入吗?

javascript - 如何从div 内部调用javascript 函数?

html - 在特定浏览器宽度下,渐变填充 div 的末尾出现白线

css - Bootstrap 响应式地分隔行

javascript - 将变量从 javascript 输出到 HTML 成本表中

javascript - 使用选择框动态更新值

database - 在 application.conf 中为 Play 2.0/anorm 加密数据库密码

postgresql - Play Framework 和 Ebean : Error in trying to obtain a connection

java - 无法将现有 Java 项目添加到我的 Play Framework 的 build.sbt