Scala Play 框架,如何处理未知 url [英] Scala Play Framework, How to handle unknown url
问题描述
嘿,我正在开发 Scala Play 框架,我需要做的是,当有人输入一些 random(unknown) url
时,这些 url 未在路由文件中定义,它们需要被路由到另一个未找到的页面,带有 404 page not found http header response
.而不是将整个路由文件显示为错误.
Hey i am working on scala play framework, what i need to do is, when someone enter some random(unknown) url
, that is not defined in routes file, they need to be routed to the some another not found page, with 404 page not found http header response
. instead of displaying the whole routes file as error.
使用 sbt : sbt 启动器版本 0.13.8
使用 scala : scalaVersion :="2.11.6"
使用播放框架 2x
using scala : scalaVersion := "2.11.6"
using play framework 2x
推荐答案
您可以在 Global.scala/Global.java
文件中覆盖这些.对于 Java,它可能类似于:
You can override these in your Global.scala / Global.java
file. For Java the could look similar to this:
public F.Promise<Result> onHandlerNotFound(Http.RequestHeader request) {
return F.Promise.<Result>pure(notFound(
Messages.get("error.routeNotFound")
));
}
这篇关于Scala Play 框架,如何处理未知 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!