【问题标题】:Jersey redirect to a default URI when resource does not exist资源不存在时泽西岛重定向到默认 URI
【发布时间】:2017-03-27 14:08:59
【问题描述】:

我正在使用 Jersey 2.22 构建一个 RESTful Web 服务,我有以下场景:

当我尝试向不存在的路径发出请求时(根本没有在资源包中实现),它会发回 404 状态,因为找不到资源(显然)。

如果发生这种情况,我想转发到默认的 URI,例如发回 index.html。

但是由于它是一个尚未实现的资源,我应该在哪里写这个验证?它是否应该在我的类中从 Application/ResourceConfig 扩展并具有 @ApplicationPath 注释?谁能告诉我一种方法或文档,甚至是明确说明的帖子?

【问题讨论】:

    标签: java rest jersey


    【解决方案1】:

    您可以在 web.xml 文件中处理 404 错误代码 -

        <error-page>
           <error-code>404</error-code>
           <location>/index.html</location>
        </error-page>
    

    详情可参考How to specify the default error page in web.xml?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 2012-07-03
      相关资源
      最近更新 更多