1

我正在尝试在我的 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 引起的......那么我该怎么做才能返回我的错误页面?

谢谢

4

1 回答 1

2

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

return "errorpages/simple503"; 

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

于 2012-06-13T12:12:54.110 回答