【问题标题】:redirect to error page, if Url is invalid in play-framework. 1.25?如果 URL 在播放框架中无效,则重定向到错误页面。 1.25?
【发布时间】:2015-05-22 09:47:40
【问题描述】:

如果用户输入无效的网址,我如何重定向到错误页面。现在,如果 URL 无效,播放会显示路线。

已按以下顺序尝试了这些路线:

   Not found
    GET /log

    These routes have been tried, in this order :


    GET       /@documentation/cheatsheet/{category}             PlayDocumentation.cheatSheet
        GET       /@documentation/modules/{module}/files/{name}     PlayDocumentation.file
        GET       /@documentation/modules/{module}/images/{name}    PlayDocumentation.image
        GET       /@documentation/modules/{module}/{id}             PlayDocumentation.page
        GET       /@documentation/files/{name}                      PlayDocumentation.file
        GET       /@documentation/images/{name}                     PlayDocumentation.image
        GET       /@documentation/{id}                              PlayDocumentation.page
        GET       /@documentation/?                                 PlayDocumentation.index
        GET       /public/                                          staticDir:public

出于多种原因,我确实想向用户显示路线。如何重定向到错误页面?

【问题讨论】:

  • 你尝试过全局对象吗?

标签: playframework playframework-1.x


【解决方案1】:

您可以修改提供的 app/views/errors/404.html 以提供不同的 404 视图。

为了便于调试,路由列表应该只在 DEV 模式下显示。在 PROD 模式下,用户应该只会看到“未找到”。

或者,您可以在自定义插件 (https://www.playframework.com/documentation/1.2.5/api/play/PlayPlugin.html) 中实现 afterActionInvocation(),该插件会检查响应状态代码 404,然后重定向到完全不同的路由。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-21
    相关资源
    最近更新 更多