【问题标题】:Simulate the http 503 status with tomcat and spring用tomcat和spring模拟http 503状态
【发布时间】:2012-06-13 20:12:54
【问题描述】:

我正在尝试在我的 spring 应用程序和 tomcat 中模拟 http 503 状态。所以我创建了一个控制器:

@RequestMapping(value = "/503", method = RequestMethod.GET)
public String error(final HttpServletRequest request, final HttpServletResponse response, final ModelMap model)
{

    response.setStatus(503);
    return null;
}

我在 web xml 中设置了过滤器:

<error-page>
    <error-code>503</error-code>
    <location>/WEB-INF/views/errorpages/simple503.jsp</location>
</error-page>

当我调用 /503 控制器时,会显示典型的 503 tomcat 页面(没有我想显示的页面)并称为我的 404 控制器。

我想这是由 503 控制器中的 return null 引起的......那么我该怎么做才能返回我的错误页面?

谢谢

【问题讨论】:

    标签: spring http tomcat


    【解决方案1】:

    您可以(假设您的视图处理程序识别字符串):

    return "errorpages/simple503"; 
    

    并使用 @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) 注释您的控制器方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-08
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 2015-05-21
      • 2017-01-04
      • 2018-11-09
      • 2016-01-05
      相关资源
      最近更新 更多