播放 2 在过滤器中获取 url 参数
play 2 get url parameter in filter
如何在 Filter
中获取 url 参数
路线
GET /:lang/ controllers.SiteIndex.index(lang)
GET /:lang/genres/ controllers.Genres.allGenres(lang)
全球
object Global extends GlobalSettings {
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
val a = request.getQueryString("lang")
val b = request.getQueryString("language")
println("executed before every request:" + request.toString)
super.onRouteRequest(request)
}
}
如何在全局中获取参数语言并在所有操作中设置语言
我认为使用自定义操作生成器会更容易,因为 onRouteRequest 不会影响传递给您操作的参数。你可以得到类似的东西:
def myAction = ActionWithLang { req: MyCustomReqWithLang =>
...
Ok("woo " + req.myLang)
}
查看动作组合下的播放文档以获取更多信息:https://www.playframework.com/documentation/2.3.x/ScalaActionsComposition
如何在 Filter
中获取 url 参数路线
GET /:lang/ controllers.SiteIndex.index(lang)
GET /:lang/genres/ controllers.Genres.allGenres(lang)
全球
object Global extends GlobalSettings {
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
val a = request.getQueryString("lang")
val b = request.getQueryString("language")
println("executed before every request:" + request.toString)
super.onRouteRequest(request)
}
}
如何在全局中获取参数语言并在所有操作中设置语言
我认为使用自定义操作生成器会更容易,因为 onRouteRequest 不会影响传递给您操作的参数。你可以得到类似的东西:
def myAction = ActionWithLang { req: MyCustomReqWithLang =>
...
Ok("woo " + req.myLang)
}
查看动作组合下的播放文档以获取更多信息:https://www.playframework.com/documentation/2.3.x/ScalaActionsComposition