【问题标题】:how to server html pages with play如何通过播放服务器 html 页面
【发布时间】:2015-12-07 13:27:28
【问题描述】:

您好,我想从控制器提供我的 index.html 页面。而且我不希望它是一个视图,我希望它是一个纯 html 文件,我不需要播放模板引擎。

考虑以下几点:

路线:GET / controllers.MainApp.index

而路由实现是:

def index = Action { implicit request =>
   if (AuthenticatedAction.isAuthenticated) {
      Ok(controllers.Assets.at(path="/public/", file="index.html"))     
    }    
     else Redirect(controllers.routes.Authentication.login())  }

我收到以下错误:

Cannot write an instance of play.api.mvc.Action[play.api.mvc.AnyContent] to HTTP response. Try to define a Writeable[play.api.mvc.Action[play.api.mvc.AnyContent]]

有没有办法提供这样的 html 页面?

一个可能的解决方案是这样做:

路线:GET /*file controllers.Assets.versioned(path="/public", file: Asset)

然后从控制器返回:

Redirect("/index.html")

这给了我一个我不想要的 url 路径:

http://localhost:9000/index.html#/

谢谢

【问题讨论】:

    标签: html scala playframework


    【解决方案1】:

    我认为解决办法是返回

    controllers.Assets.at(path="/public/", file="index.html")
    

    而不是

    Ok(controllers.Assets.at(path="/public/", file="index.html"))
    

    at 方法已经返回了一个 Result,所以这里不需要使用 Ok。

    【讨论】:

      猜你喜欢
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-12
      相关资源
      最近更新 更多