3

我有一个可以装饰页面的 Sitemesh 过滤器。我已经配置了一个 Spring exceptionResolver,以便所有错误都会转到一个名为的视图error,然后WEB-INF/jsp/error.jsp通过InternalResourceViewResolver.

现在错误页面由sitemesh装饰,我想将其排除在装饰之外。使用<exclude>sitemesh 的标签decorator.xml不起作用。因为传入的 url 可能/app/login.html和 sitemesh 一样正常,并且已经捕获并装饰了它。

我注意到在 Spring 中,如果我有一个@ResponseBodyfor ajax 请求,它将绕过 Sitemesh 的装饰。我想知道它是如何工作的?我errorResolver也可以在绕过站点网格中做点什么吗?

4

2 回答 2

1

可以通过exceptionResolver手动实现自己的流式输出并返回 null来完成ModelAndView

public class MyExceptionResolver extends SimpleMappingExceptionResolver{
public ModelAndView resolveException(HttpServletRequest request,
        HttpServletResponse response, Object handler, Exception ex) {

    //other things like logging...
    RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/error.jsp");
    try {
        dispatcher.forward(request, response);
        response.getOutputStream().flush();
    } catch (ServletException e) {
        log.error(e);
    } catch (IOException e) {
        log.error(e);
    }
    return null;
}
于 2011-05-17T09:53:41.393 回答
0

At least in SiteMesh 3 this type of exclude works (sitemesh3.xml)

<sitemesh>
  <mime-type>text/html</mime-type>

  <mapping path="/*" decorator="/WEB-INF/sitemesh/decorator.jsp" />
  <mapping path="/app/login.html" exclude="true"/>

</sitemesh>

This is tried in Spring 3. I hope this helped you.

于 2011-08-04T09:45:12.790 回答