How to create a custom 404 page handler with Play 2.0?

后端 未结 7 2180
故里飘歌
故里飘歌 2021-01-03 19:22

What’s the preferred way to handle 404 errors with Play 2.0 and show a nice templated view?

7条回答
  •  余生分开走
    2021-01-03 20:08

    This works in 2.2.3 Play - Java

    public Promise onHandlerNotFound(RequestHeader request) {
        return Promisepure(Results.notFound(views.html.notFound404.render()));
    }
    

    html should be within /views/notFound404.scala.html Dont forget to add Results.notFounf() and import play.mvc.Results;

提交回复
热议问题